Well job for today was to convert a load of virtual machines from good old eager zero to thin, now the hard way to do this is to do every one individually by hand.. As you can imagine that not exactly a good use of our time so lets automate this process and give ourselves some time for a coffee instead.

The code below is really very basic but does the job, its a straight forward storage vMotion between 2 datastores to do the conversion process and then a nice move back to the original store (in essence we are using the $THINSTORE as a bit of a buffer).

1
2
3
4
5
6
7
8
9
10
11
12
$THICKSTORE = "thick"
$THINSTORE = "thin"
$VMs = Get-datastore | Where {$_.name -like $THICKSTORE } | Get-VM

Foreach ($VM in $VMs){
Write-Host "VM: "$VM "Moving from: "$THICKSTORE "To: " $THINSTORE
Move-VM $VM -Datastore $THINSTORE -DiskStorageFormat Thin

# NOW its Thin move it back to original store
Write-Host "VM: "$VM "Moving from: "$THINSTORE "To: " $THICKSTORE
Move-VM $VM -Datastore $THICKSTORE
}

Well it seems to have done the trick so guess i am due that coffee now.