Thursday, September 25, 2014

Mass storage vMotion: Migrate VMs serially/sequentially/one at a time between datastores using powercli

So you got a new SAN, or you bought some more disk and attached it.  Storage VMotion is great - but who wants to sit around and click and migrate tens or hundreds of VMs?

I did a little googling, because I'm lazy.  I didn't find anything (but I didn't look that hard) that did what I wanted it to do.  I did find the following one-liner here.

Get-VM -Datastore SOURCEDATASTORE| Move-VM -Datastore DESTINATIONDATASTORE -DiskStorageFormat thin

This one liner is great, but the problem is that it will slam your storage system by executing all the svmotions at once.  That's okay if you have two or three VMs, but presumably you bought more storage because of a controller or disk constraint, and this will further deteriorate your storage performance.

Well, how do we solve that?  Let's just move one VM at a time.

If you want to move all the VMs from a datastore sequentially and one at a time, take this script block, modify the variables for your environment, save it as a .ps1, and you'll be all set:


connect-viserver vcenter.domain.tld
$sourcedatastore = "SOURCEDATASTORE"
$destinationdatastore = "DESTINATIONDATASTORE"

$vms = Get-VM -Datastore $sourcedatastore
foreach($vm in $vms){
Move-VM -VM (Get-VM -Name $vm) -Datastore $destinationdatastore -DiskStorageFormat thin
}

This will move all the VMs, but one at a time...further delaying the onset of your carpal tunnel syndrome. You can thank me another day :)


3 comments:

  1. Thank you so much for this. Huge 200 TB storage move to new storage system and need to control how many move at once...and this does the trick well.

    ReplyDelete
  2. Just what i needed. Not complaining at all, but would be great to have it write-host a Start msg with VM name, then an End msg after each VM is moved.

    ReplyDelete
  3. I am trying to adapt the script to move VMs from a single datastore to a datastore cluster. Is there an automated method to split the VMs across the datastores?

    ReplyDelete

Featured Post

Remove 3D Objects and other annoying folders on Windows 10

 Microsoft just keeps adding more crap to clutter up the navigation in Windows 10.  Seriously, who needs a 3D Objects folder?  The tiny perc...