- Create a list of VMs (in my case all of them of type Thick)
- Copy utility files to each VM
- Move each VM to the host with the local SSD drives using vmotion
- Move each VM to the SSD datastore using svmotion
- Defrag the VM's drives
- Zero out any free space on the VM's drives to enable the best results on the conversion to thin disks
- Move each VM back to its original datastore
I used a couple Microsoft utilities to accomplish this:
I also used a simple batch file "cleanhd.cmd" to accept the EULA and iterate thru all hard drives:
reg add HKCU\Software\Sysinternals\SDelete /v EulaAccepted /d 1 /t REG_DWORD /f
FOR %%I IN (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @if exist "%%I:\System Volume Information" defrag %%I: -f -v
FOR %%I IN (B C D E F G H I J K L M N O P Q R S T U V W X Y Z) DO @if exist "%%I:\System Volume Information" sdelete -c %%I:
Here is the PowerCLI that handles the work:
$vms=Get-VM | Get-HardDisk | where-object {$_.ProvisionedSpaceGB -lt 100} | select-object -expandproperty Parent -unique | sort
Foreach($vm in $vms){
$SSDDatastore=get-datastore 'datastore-ssd'
$SSDHost=get-vmhost 'ssdhost'
$originalds=($vm | get-datastore)
copy-item c:\windows\sdelete.exe -destination (convert-path ('\\' + $vm.Name + '\' + 'admin$'))
copy-item c:\windows\cleanhd.cmd -destination (convert-path ('\\' + $vm.Name + '\' + 'admin$'))
move-vm -destination $SSDHost -vm $vm
$vm | Get-HardDisk | set-harddisk -datastore $SSDDatastore -storageformat thin
psexec \\$VM cleanhd.cmd
$vm | Get-HardDisk | set-harddisk -datastore $originalds -storageformat thin}