Virtual Machine Storage Migration
Use PowerShell to move all virtual machines on a host using certain storage to a new location.
John Savill
September 2, 2014
1 Min Read
Q: How can I perform a migration for all storage in a particular location?
A: I recently needed to move all my virtual storage from one location to another for a particular Hyper-V host. The following PowerShell code turned out to be the easiest method of accomplishing my task:
$VMstoMove = Get-VM | Get-VMHardDiskDrive | where {$_.Path.StartsWith("C:ClusterStorageVMs")} foreach ($VM in $VMstoMove){ write-host $VM.VMName $vmobj = get-vm -Name $VM.VMName $newpath = "C:ClusterStorageStorageSpace_VMs" + $VM.VMName Move-VMStorage -DestinationStoragePath $newpath -VM $vmobj}
You might want to tweak this code for your requirements. The first line of code finds all the VHDs stored in the specified location and then performs a storage migration for each of them.
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