Live Migrations in PowerShell

If you get a hardware warning when attempting a live migration confirm that the Processor of the VM is configured, under Processor > Compatibility, to allow Migration to a different processor version. This is just a check box but the VM needs to be off to change it!

If you still get the error confirm that the virtual switch name on both Hyper-V boxes is the same. You will need to reboot the VM after you have updated them if you change the one on the Hyper-V host where the VM is currently.

Full powershell…

get-VM "VMtobeMoved" -ComputerName "NameofHyperVHost" | move-vm -DestinationHost "NameofDestinationHost" -VirtualMachinePath "D:\hyper-v\virtual machines\blah" -snapshotfilepath "D:\hyper-v\virtual machines\blah\" -SmartPagingFilePath "D:\hyper-v\virtual machines\blah\" -VHDs @(@{"sourcefilepath" = "c:\virtualmachines\blah\blah.vhd"; "destinationfilepath" = "D:\hyper-v\virtual hard disks\blah.vhd"}, @{"sourcefilepath" = "c:\virtualmachines\blah\virtual Hard Disks\blah-Data.vhd"; "destinationfilepath" = "D:\hyper-v\virtual hard disks\blah-Data.vhd"})

Hopefully you are sensible and all your Hyper-V files (machine, VHDs, snapshots, paging file, …) are all in one location. In which case you can use this much simpler script:

Get-VM "VMtobeMoved" -ComputerName "NameofHyperVHost" | Move-VM -DestinationHost "NameofDestinationHost" -IncludeStorage -DestinationStoragePath "D:\VMtobeMoved"