Skip navigation
virtual machines

Storage Migration of 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-Unique

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