I wrote this post a while back on how to use the API to convert VMs from thin to thick, which you could also go from thick to thin using it. I had written it because I was trying to use the inflate function, which isn’t allow against powered on VMs.
It was pointed out by a reader that I could have simply used Move-VM to accomplish the same task. This is great, shows how a second set of eyes and a different perspective can help you solve the problem. You could simply do
1 |
Move-VM vmservername -Datastore datastorename -DiskStorageFormat thick |
and it will move your VM to the specified datastore and convert to thick. You could use either thin or thick.
If you wanted to move every VM on a datastore, say Datastore1, to a new datastore, say Datastore2, and convert all of them to either thin or thick, you could do it like this:
1 |
Get-VM -Datastore Datastore1 | Move-VM -Datastore Datastore2 -DiskStorageFormat thick |
You cannot specify the current datastore as the destination datastore, though. It will complete, but it will not convert your VM’s disk format, you have to actually Storage vMotion the VM to a different datastore. It basically validates the destination datastore is where it currently resides and exits without trying to convert your vmdk.
You could then take it a step farther and make a function that supports parameters, like if you wanted to move VMs on multiple datastores, or a given list of VMs to a specific datastore. For instance, you could create something like “convert-vms.ps1” and run it like this
1 |
convert-vms.ps1 -vms ("vm1",vm2","vm3","vm4") -destination datastore2 -thick |
and it would move all four VMs to datastore2 and convert them to thick in the process. Or something like
1 |
convert-vms.ps1 -source ("datastore1","datastore2") -destination datastore3 -thin |
That would move all VMs from datastores 1 & 2 and thin provision them on datastore3.
If anyone’s interested in the actual script/function, let me know and I can put one together fairly quickly.
Very useful. Thanks!
Hi I need to migrate all the VMs from one data store to another data store and convert all the machines to Thick Lazy.
Another method for servers in a cluster
Get-Cluster “New Cluster” |Get-VM |?{($_.extensiondata.config.datastoreurl|?{$_.name -eq “DATASTOREOLD”})} |ForEach-Object {Move-VM -VM $_.Name -Datastore “DATASTORENEW” -RunAsync}
that works, but seems like a bit much. You can shorten it to look like this:
get-cluster | get-vm | ? {$_.ExtensionData.config.datastoreurl.name -eq "old-datastore"} | move-vm -Datastore "new-datastore"
And of course you can add in the -runasync or -diskstorageformat thick/thin.
I am looking for 2 short script
1) to migrate all VMs from one datastore to another, but not more than 3 at a time.
2) to migrate all powered off VMs from one datastore cluster to another, only 3 migration at a time.
Can anyone help me