virtual storage

Virtual Machine Storage Migration

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:\ClusterStorage\VMs")} 

foreach ($VM in $VMstoMove)
{
    write-host $VM.VMName
    $vmobj = get-vm -Name $VM.VMName
    $newpath = "C:\ClusterStorage\StorageSpace_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.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish