Q: How can I perform a storage migration of all virtual machines that have VHDs on a certain hard disk?
A: The following PowerShell code lists all virtual machines on a host, then looks for all VHDs using a certain path. If a match is found, it moves the virtual machine to a new path specified in the script and includes the name of the virtual machine in the new path.
$VMstoMove = Get-VM | Get-VMHardDiskDrive | where {$_.Path.StartsWith("C:\Path")} | Select-Object -ExpandProperty VMName | Get-Unique foreach ($VM in $VMstoMove) { write-host $VM $vmobj = get-vm -Name $VM $newpath = "C:\ClusterStorage\VMs\" + $VM Move-VMStorage -DestinationStoragePath $newpath -VM $vmobj }
0 comments
Hide comments