Hyper-V Live Migration with PowerShell

September 6, 2019
I need to move a VM to my newly created Hyper-V Server 2019 named HOST1.
On both the old and new Hyper-V host, I run these PowerShell commands
Enable-VMMigration
Set-VMMigrationNetwork 192.168.1.1
Set-VMHost -VirtualMachineMigrationAuthenticationType Kerberos

Then on the old host, I run this PowerShell command to move DC02 VM to the new host

Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath "D:\Hyper-V\DC02"
However, I received an error
Move-VM : The operation on computer 'HOST1' failed: WinRM cannot process the request. The following error with
errorcode 0x8009030e occurred while using Kerberos authentication: A specified logon session does not exist. It may
already have been terminated.
 Possible causes are:
  -The user name or password specified are invalid.
  -Kerberos is used when no authentication method and no user name are specified.
  -Kerberos accepts domain user names, but not local user names.
  -The Service Principal Name (SPN) for the remote computer name and port does not exist.
  -The client and remote computers are in different domains and there is no trust between the two domains.
 After checking for the above issues, try the following:
  -Check the Event Viewer for events related to authentication.
  -Change the authentication method; add the destination computer to the WinRM TrustedHosts configuration setting or
use HTTPS transport.
 Note that computers in the TrustedHosts list might not be authenticated.
   -For more information about WinRM configuration, run the following command: winrm help config.
    + CategoryInfo          : NotSpecified: (:) [Move-VM], VirtualizationException
    + FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.MoveVM
Let's fix this by granting necessary delegation.
Open Active Directory Users and Computers.
Right click on the destintation Hyper-V server, HOST1, and go to Properties and then Delegation tab.
Select Trust this computer for delegation to specified services only and Use any authentication protocol Click Add, choose computer account of the Hyper-V server that currently hosts the VM you want to move, and add cifs, which is required to migrate storage, and Microsoft Virtual System Migration Service, which is required to migrate virtual machine.
We should be good now. Let's move it
Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath D:\Hyper-V\DC02
I'm getting another errror message:
Move-VM : Virtual machine migration operation failed at migration destination.
The virtual machine 'DC02' is not compatible with physical computer 'HOST1'.
Virtual machine migration operation for 'DC02' failed at migration destination 'HOST1.dccb.net'. (Virtual
machine ID XXXXXXXXX-XXXX-4F76-B23F-D5D54054B5C9)
The virtual machine 'DC02' is not compatible with physical computer 'HOST1'. (Virtual machine ID
A136B5C6-4DC8-4F76-B23F-D5D54054B5C9)
Could not find Ethernet switch 'Intel Virtual Switch'.
At line:1 char:1
+ Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath D:\Hyper ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Move-VM], VirtualizationException
    + FullyQualifiedErrorId : Unspecified,Microsoft.HyperV.PowerShell.Commands.MoveVM
Oh, I have a name mismatch for the virtual switch. Let's check to make sure
Compare-VM -Name DC02 -DestinationHost HOST1
VM                 : VirtualMachine (Name = 'DC02') [Id = 'xxxxxxxx-xxxx-4910-97d0-30dc86a4ebaa']
OperationType      : MoveVirtualMachine
Destination        : HOST1
Path               :
SnapshotPath       :
VhdDestinationPath :
VhdSourcePath      :
Incompatibilities  : {21026, 24000, 33012, 40010}
CheckpointPath     :
I'm going to get a compatibility report and store it in a variable named $Report

$Report = Compare-VM -Name DC02 -DestinationHost HOST1
$Report.Incompatibilities
Message
-------
Virtual machine migration operation for 'DC02' failed at migration destination 'HOST1.dccb.net'. (V...
The virtual machine 'DC02' is not compatible with physical computer 'HOST1'. (Virtual machine ID xxxxxxxx-764D-...
Could not find Ethernet switch 'Intel Virtual Switch'.
Virtual Hard Disk file not found.
4 incompabilities, one line for each incompatibility.
That means 33012 is Could not find Ethernet switch 'Intel Virtual Switch'.
Let's connect the VM to a virtual switch named externalSwitch, which I have already created for HOST1
$Report.Incompatibilities | where MessageID -eq 33012 | foreach `
{ Connect-VMNetworkAdapter -VMNetworkAdapter $_.Source -SwitchName externalSwitch -Passthru }
Name            IsManagementOs VMName    SwitchName     MacAddress   Status IPAddresses
----            -------------- ------    ----------     ----------   ------ -----------
Network Adapter False          DC02 externalSwitch 00155D01EF02 {Ok}   {192.168.1.11}
That should do it. Let's move it now
Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath D:\Hyper-V\DC02
Move-VM : Virtual machine migration operation failed at migration destination.
Synthetic SCSI Controller (Instance ID XXXXXXXX-XXXX-4897-AB34-363AF43BA763): Failed to restore with Error 'The system cannot find the file specified.'.
Attachment 'D:\ISO\W2016-1607.ISO' could not be found due to error: 'The system cannot find the file specified.'.
Virtual machine migration operation for 'DC02' failed at migration destination 'HOST1.dccb.net'. (Virtual machine ID
XXXXXXXX-XXXX-4910-97D0-30DC86A4EBAA)
'DC02' Synthetic SCSI Controller (Instance ID XXXXXXXX-XXXX-4897-AB34-363AF43BA763): Failed to restore with Error 'The system cannot find the file
specified.' (0x80070002). (Virtual machine ID XXXXXXXX-XXXX-4910-97D0-30DC86A4EBAA)
'DC02': Attachment 'D:\ISO\W2016-1607.ISO' could not be found due to error: 'The system cannot find the file specified.' (0x80070002). (Virtual machine
ID XXXXXXXX-XXXX-4910-97D0-30DC86A4EBAA)
At line:1 char:1
+ Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath D:\ ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (:) [Move-VM], VirtualizationException
    + FullyQualifiedErrorId : ObjectNotFound,Microsoft.HyperV.PowerShell.Commands.MoveVM
Ah, I forgot to unmount the ISO
Get-VMDvdDrive –Vmname DC02
VMName    ControllerType ControllerNumber ControllerLocation DvdMediaType Path
------    -------------- ---------------- ------------------ ------------ ----
DC02 SCSI           0                1                  ISO          D:\ISO\W2016-1607.ISO
Set-VMDvdDrive -VMName DC02 -ControllerNumber 0 -ControllerLocation 1 -Path $null
Get-VMDvdDrive –Vmname DC02
VMName    ControllerType ControllerNumber ControllerLocation DvdMediaType Path
------    -------------- ---------------- ------------------ ------------ ----
DC02 SCSI           0                1                  None
OK, now let's move the virtual machine.
Move-VM "DC02" HOST1 -IncludeStorage -DestinationStoragePath D:\Hyper-V\DC02
All done.