I Love PowerCLI!

I had a requirement to add an additional virtual hard disk to 50 virtual machines. This was going to be a painful job through the vSphere Client so I resorted to PowerCLI.

The virtual machines all had a name starting PerfTest with a number at the end from 1 through to 50, e.g. PerfTest1, PerfTest2, ….., PerfTest50. The new virtual hard disks all needed to be created on a datastore separate to the virtual machine, named XIV_PERFTEST_NOREP and each of them needed to be 8GB.

I was able to create and add all of these new virtual hard disk with a single line of PowerCLI

For ($i=1;$i le 50;i++) {New-HardDisk –VM PerfTest$i –CapacityGB 8 –Datastore XIV_PERFTEST_NOREP}

This entry was posted in PowerCLI, Powershell, VMware. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s