I have about 100 VM's in a resource pool called "Archive" for... well, Archiving. These VM's are currently powered off but every now and then one will get pulled out for a developer to work on (they're mostly VM's with customer customizations so they're modified about once a year). I'm quickly running out of space on this SAN but all of the disks are thick provisioned and disk utilization is maybe 20-30% on average. Also, I want to move them to a new large datastore I created for them.
Obviously I can choose Migrate > Change Datastore > Thin Provision Format in vSphere and I'm done. However, it would be nice not to have to do this 100 times.
Move-VM doesn't seem to be capable of this and I haven't been able to find a workaround. Is there a way to convert to thin and then Move-VM maybe? Or am I just going about this all wrong.
Thanks!
Can you try this script?
It'll relocate vms to "EMCSAN:Datastore01" datastore trying to change storage format to Thin
$dsView = Get-Datastore -Name "EMCSAN:Datastore01" | Get-View -Property Name Get-VM <archive_vm_names> | % { $vmView = $_ | Get-View -Property Name $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $dsView.MoRef $spec.transform = "sparse" $vmView.RelocateVM($spec, $null) }
/Yasen
Maybe it get you wrong, but you can mark all 100 VMs and sVmotion --> migrate them at bunch.
Hi,
Move-VM and Set-HardDisk cmdltes does not support changing disk format for now. You can use VirtualMachine RelocateVM_Task method to change disk type i .e.
Get-VM <archive_vm_names> | % { $dsView = Get-Datastore -VM $_ | Get-View -Property Name $hostView = Get-VMhost -VM $_ | Get-View -Property Name $vmView = $_ | Get-View -Property Name $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $dsView.MoRef $spec.host = $hostView.MoRef $spec.transform = "sparse" $vmView.RelocateVM($spec, $null) }
P.S If all vms are on a same host and datastore you can optimize the script moving all logic before foreach loop and just call RelocateVM for each of vms:
$dsView = Get-Datastore <datastore_name> | Get-View -Property Name $hostView = Get-VMhost <datastore_name> | Get-View -Property Name $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $dsView.MoRef $spec.host = $hostView.MoRef $spec.transform = "sparse" Get-VM <archive_vm_names> | Get-View -Property Name | %{ $_.RelocateVM($spec, $null) }
/Yasen
Thanks for the help so far! I think I'm missing something though...
I entered a test VM name where <archive_vm_names> is and ran the script. It runs "sucessfully" and I see "Relocate virtual machine" pop up in the vSphere client but nothing appears to have really happened. Am I missing a step? Maybe my setup is preventing something in this process? This particular server's storage is a FC SAN that is directly connected (hence svmotion not being available) and partitioned into multiple datastores. The archive datastore is "EMCSAN:Datastore01" and the VM's that are thick provisioned are on the other "EMCSAN:DatastoreXX" datastores.
Thanks again for your help on this somewhat unique issue.
Allen
Can you try this script?
It'll relocate vms to "EMCSAN:Datastore01" datastore trying to change storage format to Thin
$dsView = Get-Datastore -Name "EMCSAN:Datastore01" | Get-View -Property Name Get-VM <archive_vm_names> | % { $vmView = $_ | Get-View -Property Name $spec = New-Object VMware.Vim.VirtualMachineRelocateSpec $spec.datastore = $dsView.MoRef $spec.transform = "sparse" $vmView.RelocateVM($spec, $null) }
/Yasen
Yasen, you're a freaking genious! It worked perfectly I'll incorperate it into a script to run overnight on the rest of the VM's. You just saved me a TON of time.
Then I just need to look into what it is that you've just showed me so I can understand it as well, LOL.
Thanks again!
Allen