Thursday, April 28, 2011

My first blog and it's on PowerCLI...

So this is my first ever blog and I'm using it to record some PowerCLI syntax for storage vMotion automation. Is that cool or boring? I'm sure it must be boring in the extreme to anyone who doesn't have to spend hours migrating LUN's like me.

What I really wanted to acheive with these scripts/commands was to migrate all virtual machines from an old LUN to a new LUN. I have found out a simple way to do this with the following.

First command:

Get-Datastore "datastorename" | Get-VM | '
Move-VM -Datastore (Get-Datastore "datastorename") -DiskStorageFormat "Thin" -RunAsync

This script will get all virtual machines on a specified named datastore then sequentially send a vMotion command to each virtual machine and convert all disks to thin provisioning at the same time.
The -RunAsync command will tell the command line not to wait for the task to finish, but to have it processed by vSphere so I can continue working on the command line.

Second command:

Get-VM "vm_name" | '
Move-VM -Datastore (Get-Datastore "datastorename") -DiskStorageFormat "Thin" -RunAsync

This script is similar to the above but will do a single named virtual machine which is handy for targeting a couple of virtual machines that I want sent to a different datastore before the bulk of the moves are kicked off.

More posts to come in the future, mostly to do with my work on VMware solutions.

No comments:

Post a Comment