Written by 8:41 pm Microsoft, Microsoft Azure, PowerShell, Virtualization, Windows Server • 4 Comments

Move multipe Hyper-V Virtual Machines with Live Storage Migration via Windows PowerShell

PowerShell

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
}

Tags: , , , , , , , , Last modified: November 1, 2018
Close Search Window
Close