Adding and Removing Items from a PowerShell Array

Adding and removing Items from a PowerShell array is a topic which can lead to some confusion, so here are a few tips for you. Create an array and we will note the type System.Array: $Fruits = "Apple","Pear","Banana","Orange" $Fruits.GetType() However, if we try to Add or Remove items to the array we get errors that the “Collection was of a fixed size” $Fruits.Add("Kiwi") $Fruits.Remove("Apple") $Fruits.IsFixedSize We can see that the array we originally created is of a fixed size.

London VMUG Thursday 23rd Jan 2014

The next London VMUG takes place on Thursday 23rd Jan 2014, you can register here. The below agenda looks great with all the current hot topics covered; vCAC, VSAN, vCHS, NSX, homelabs and Lego. So I’ll be heading there soon with my friends above and will see you there :-)

Testing for Admin Privileges in PowerShell

Sometimes when running a PowerShell script you may need to test at the beginning whether the process it was called from had Windows admin privileges in order to be able to achieve what it needs to do. Prior to PowerShell v4 I had used something along the lines of the following to test for this condition - not the most obvious piece of code ever to be fair: function Test-IsAdmin { (\[Security.

Winter Scripting Games 2014

If you’re looking to learn or improve on existing skills as part of a new year goal and one of those in PowerShell, then you may find it useful to check out the Winter Scripting Games 2014. When you are looking to improve your scripting skills it can sometimes be tricky if you don’t have a practical problem to solve. By taking part in these games you will have a number of opportunities to apply your skills to real problems.

vSphere: Importing a CentOS VM Exported as a VMDK from KVM

I was recently given a VMDK file which I was informed had been exported from a KVM system and needed to be used to create a VM in vSphere. Initially I thought this would be quite a straightforward task, but turned out to be a bit of an effort, so thought I would share it here since most of the info on the interwebs seems to be for moving VMs in the other direction.

VMware Converter: Permission to perform this operation was denied

While attempting to carry out a V2V using VMware Converter I had a permissions related issue when selecting the source machine: Permission to perform this operation was denied I triple-checked my permissions within vCenter were sufficient to carry out a V2V, even temporarily granting my own account with the Administrator role directly to the location in question, but still received the above error. I stumbled across this VMware Community posting which suggested that granting local Administrator rights to the account I was using on the Windows server where VMware Converter was running from might help.

PowerCLI In The Enterprise: Breaking The Magician’s Code & Function Templates

At today’s #UKVMUG I presented on the topic: PowerCLI In The Enterprise: Breaking The Magician’s Code. Below are the slides from the session: During the session I discussed breaking your PowerShell code down into functions and modules. To aid with this I am posting the 6 function templates I use which cover many of the typical scenarios I write a function for and enable the rapid creation of these functions since much of the code is typically repeated.

VMUG iOS and Android App

I was made aware today that there is a VMUG App for iOS and Android. According to the description it looks like it will be pretty useful if you are attending a VMUG: Attending a VMUG User Conference. Download the event app before you go to have all of your conference details at your fingertips. The app will provide you with real-time updates on sessions, speakers, exhibitors, and networking opportunities. You’ll be able to take notes, follow Tweets, connect with other attendees, provide session feedback, and more, all from your phone.

Problems With VM After Failed Snapshot-Based Backup - Unable to Access File Since It Is Locked

Whatever backup solution you use to backup your virtual infrastructure with, you may sometimes end up with VM snapshots that need to be cleaned up. After a backup failure alert, I use the following PowerCLI one-liners to quickly identify and remove snapshots left behind (by say Netapp SMVI). Get-VM | Get-Snapshot | Where-Object {$\_.Name -like 'smvi\*'} | ft VM,Name,Created -AutoSize Get-VM | Get-Snapshot | Where-Object {$\_.Name -like 'smvi\*'} | Remove-Snapshot -RunAsync -Confirm:$false Recently I had an instance where post a backup failure the snapshot failed to remove with the error Unable to communicate with the remote host, since it is disconnected.

Creating PowerShell ISE v3 (and later) Code Snippets

When using the PowerShell ISE , similar to other scripting editors, you have access to what are known as ‘code snippets’. These are quick start ways to generate frequently used code, for instance if there is something you use regularly and can never remember the syntax for, or maybe it is too long to be practical to remember it. PowerShell ships with some default snippets and it is also possible to add some custom snippets of your own.