Storage Migration of Virtual Machines

Easily move all storage for virtual machines on a certain disk.

John Savill

September 6, 2014

1 Min Read
virtual machines

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-Uniqueforeach ($VM in $VMstoMove){    write-host $VM    $vmobj = get-vm -Name $VM    $newpath = "C:ClusterStorageVMs" + $VM    Move-VMStorage -DestinationStoragePath $newpath -VM $vmobj}

About the Author

Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like