PowerShell script to migrate a virtual machine

This is a small PowerShell script which allows you to migrate a virtual machine.
For this script to work, the Hyper-V PowerShell module has to be loaded.

#Usage: script.ps1 <vm name> <target path> <target server>
#Example: script.ps1 VM001 E:\Hyper-V Hyperv2
function MigrateVM ($VMName, $TargetPath, $TargetServer)
Get-VM -server $VM -vm $VMName | invoke-vmshutdown -force -Wait | Export-VM -VM $VMName -Path $TargetPath -Wait |  Get-VM -server $TargetServer -vm $VMName | Start-VM -Wait

Leave a Reply

Your email address will not be published. Required fields are marked *