Site Loader

Hi,

Need to migrate a standalone Hyper-v host? Here is a powershell workflow that could help you.

Run this script from the source host

workflow Livemigrate {

    param(
        [string]$DestinationHostname,
        [string]$StoragePath,
        [int]$throttlelimit
    )
            if(!$throttlelimit){$throttlelimit = '2'}
            #removes \ at the end
            if ($StoragePath.EndsWith("\") -eq $true){$StoragePath = $StoragePath.Substring(0,$StoragePath.Length-1)}

            #replaces \\ for \
            $StoragePath = $StoragePath.Replace("\\","\")
    
            #correct the start of the UNC in all cases
            $StoragePath = $StoragePath.TrimStart("\")
            $StoragePath = $StoragePath.Insert(0,"\\")

    $VMnames = Get-VM

    foreach -parallel -throttlelimit $throttlelimit ($virtualMachine in $VMnames){
        $VMName = $virtualMachine.VMName
        $DestinationStoragePath = "$StoragePath\$VMName"
        Move-VM -IncludeStorage -DestinationHost $DestinationHostname -name $VMName -DestinationStoragePath $DestinationStoragePath
    }

}

Livemigrate -DestinationHostname 'HVHost02' -StoragePath 'D:\VirtualMachines' -throttlelimit 3

throttlelimit parameter, make sure you have enough bandwidth when you migrate the VM’s. Based on my experience on a 1Gb link you can do 2 parallel machine without interfering the end user.

Sander