Another quick & dirty fast publish:

 

When live migrating a VM from one Hyper-V to another Hyper-V when the virtual switch names are different, using the GUI you get a prompt to select the swtich on the target host. Using Powershell “Move-VM” fails and there is no option to specify the target switch name.

 

A way around this is using the Compare-VM cmdlet. Below is part of a quick and dirty script that achieved my goal.

Predefined variables: $VMName, $Switch & $TargetHost

 

$VMReport = Compare-VM -Name $VMName –DestinationHost $TargetHost

$VMReport.Incompatibilities | ?{$_.MessageID -eq 33012} | %{Connect-VMNetworkAdapter $_.source -SwitchName $Switch}

Move-VM $VMReport -AsJob

 

 

This will live migrate the VM defined to the target host and change the virtual switch

 

Edit: 3/6/2015

 

Do the above with a Out-GridView

 

$targethost = Read-Host "Name of target Hyper-V Host"
$VMS = Get-VM | Out-Gridview -Title "Running VM’s" -Passthru

ForEach ($VM in $VMS)
    {
    $VMReport = Compare-VM -Name $VM.Name -DestinationHost $targethost
    $VMReport.Incompatibilities | ?{$_.MessageID -eq 33012} | %{Connect-VMNetworkAdapter $_.source -SwitchName "LSwitch-Hosts"}
    Move-VM $VMReport -AsJob
    }

 

 

Cheers’

Dan

Leave A Comment