Well I was working in on a Private Cloud Deployment where we had some temporary storage for our Hyper-V Virtual Machines and after we got the right storage ready, which was btw a Windows Server Scale-Out File Server Cluster running with Storage Spaces and DataON JBOD chassis, we had to migrate the storage of all virtual machines running on our Hyper-V hosts. Since Windows Server 2012 offers Live Storage Migration which allows us to move the Virtual Machine to a different storage location without downtime we would use that. But if you have to move around 20 virtual machines you think twice if you want to move that via the Hyper-V Manager GUI or Windows PowerShell.
Here is a pretty simple PowerShell foreach loop which moves the storage of all virtual machines running on the Hyper-V host.
#New Storage Location $StoragePath = "\\SMB01\VMs01\" #VMs which will be migrated Get-VM will migrate all VMs $VMs = Get-VM Foreach ($VM in $VMs) { $VMStorage = $StoragePath + $VM.Name Write-Host "Moving VM:" $VM.name "to" $VMStorage Move-VMStorage -VMName $VM.name -DestinationStoragePath $VMStorage }
O profiles, but if you attempt to move too much at one time, you could experience a problem. Start conservatively with your concurrent Live Storage Migrations and move up. Also remember that different times of day will affect your performance.
Here’s a one liner to do it if you want to specify just particular files. Also does it sequentially so the host doesn’t get swamped.
Just update the directory info
Get-VM | Out-GridView -Title “Select one or more VMs to move storage” -PassThru | Move-VMStorage -DestinationStoragePath “E:\VM”
Nice Robert!
Nice script which still holds up today, thanks.
You can add -Confirm if you want to prompt y/n for each VM migration:
Move-VMStorage -VMName $VM.name -DestinationStoragePath $VMStorage -Confirm