If you have the need to move multiple VM disks on a stand-alone Hyper-V server or Hyper-V cluster server, this script may help you move them. If you perform manually VM disk migration for multiple VM, you will need to finish the one VM first before you can proceed to the next VM. Hence, this can prevent you from waiting as the script will handle it and move to the next VM disks.

This is basically a loop script that will move the VM storage from the old location to the new location.

On this scenario. I will migrate the VMs storage from old CSV (cluster shared storage) volume to the new volume

Old path -> C:\ClusterStorage\NesCluDisk1\Hyper-V
New Path -> C:\ClusterStorage\NesCluDisk2\Hyper-V

I assume that the volume or the LUN is ready to use, and already connected to the all clusters nodes or host.

  1. First, format the iSCSI drive via from the one of servers. Format it as NTFS filesystem, and 64K allocation unit size.
  2. Add the disk to the cluster, and then add into Cluster Shared Storage.
  3. Once done, there will be two volumes on C:\ClusterStorage. To easy to manage the volume, rename the volume with a easy name like volume2,3 etc. In my environment, I renamed as NesCluDisk2
Get-VM -ComputerName (Get-Cluster) | Get-VMHardDiskDrive | select VMName,Path
#List of VMs needs to be moved on the cluster. Remove (get-clusternode) if want to run on the stand-alone server ##
$VMs = Get-VM -ComputerName (Get-ClusterNode) 
 
## Looping the task ##
Foreach ($VM in $VMs) {

## New directory path on the CSV ##
$VMStorage = "C:\ClusterStorage\NesCluDisk2\Hyper-V\"
Write-Host "Moving VM:" $VM.name "to" $VMStorage
Move-VMStorage -VMName $VM.name -DestinationStoragePath $VMStorage\$VM
}

The alternative way to loop the task and using a VM list, you can export the list of the VMs to a notepad, and then import it as the following:

## New directory path on the CSV ##
$VMs = Get-content "C:\Install\MoveVM\VMlist.txt"
$VMStorage = "C:\ClusterStorage\NesCluDisk2\Hyper-V\"

Foreach ($VM in $VMs) {
Write-Host "Moving VM:" $VM "to" $VMStorage
Move-VMStorage -VMName $VM -DestinationStoragePath $VMStorage\$VM
}