26 Apr
Migrate virtual machines and enable thin provisioning
I recently used this code to move a couple dozen terabytes of virtual machines from one array to another — all while enabling thin provisioning (aka sparse disk). Once the LUN migration is complete a nice little message shows up in your email. It is a very straight forward script that I thought was worth sharing.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | $startTime = get-date $sourceDS = "array1-1000" $destDS = "array2-3000" $dsView = Get-Datastore -Name $destDS | Get-View -Property Name Get-VM -Datastore $sourceDS | sort name | % { $vmView = $_ | Get-View -Property Name $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $dsView.MoRef $spec.transform = "sparse" $vmView.RelocateVM($spec, $null) } Send-MailMessage -From "vmware@mydomain.local" -SmtpServer "smtp.mydomain.local" -Subject "Migration from $sourceDS to $destDS complete" -To "me@mydomain.local" -BodyAsHtml "This task started at $($startTime.datetime.tostring()) and finished at $((get-date).datetime.tostring())" |

Posted by Emptying a VMFS datastore with PowerCLI | Christian's blog on 2012/01/26 4:14:48 PM at 10:39 am
[...] I have something different, which was a bit shorter (based on Brian‘s work), but it had a huge downside: If you have vRDMs (like I do), it converts every damn [...]