In my lab I use virtual machines a lot, and not surprisingly, sometimes I need to move around Hyper-V VMs to either a new disk volume, or just to a new folder on the same volume, because of disk space. Either way, with PowerShell that is a quite easy task. Here are a few examples:
# Move a single virtual machines to a new folder and/or disk volume
$VMName = "PC0011"
$DestinationPath = "F:\VMs"
Move-VMStorage -VMName $VMName -DestinationStoragePath "$DestinationPath\$VMName"
# Move a set of VMs to a new folder and/or disk volume
$VMs = Get-VM -Name PC*
$DestinationPath = "F:\VMs"
foreach ($VM in $VMs){
$VMName = $VM.VMName
Move-VMStorage -VMName $VMName -DestinationStoragePath "$DestinationPath\$VMName"
}
Please note that the Move-VMStorage cmdlet will create the destination folder if it does not exist, but it does not remove the original VM folder when migration is done. The original VM folder will be empty from a data point of view, but the folder structure will still be there. So either update the script to delete the old folder too, or do it manually after moving the VM.
Happy Deployment / Johan