Sashkin - Fotolia
You can use Hyper-V Manager to live migrate VMs one by one, but to live-migrate multiple VMs simultaneously, you have to use PowerShell. In this article, we provide a few PowerShell examples to help you live-migrate Hyper-V VMs operating in and outside of a failover cluster.
PowerShell provides the Move-VM PowerShell cmdlet to live-migrate a Hyper-V VM running on one host to another host, but Move-VM only works for VMs operating outside of a Hyper-V failover cluster. For example, VMs operating in a Hyper-V shared nothing live migration model are live-migrated using the following PowerShell command:
Move-VM "SQLVM" -DestinationHost <Hyper-VHostName> -DestinationStoragePath E:\MyVM1
The command shown above moves SQLVM to the Hyper-V host specified in the -DestinationHost parameter. While that command moves a single VM, the command shown below moves all VMs running on the local Hyper-V host to a remote Hyper-V host:
Get-VM -ComputerName <LostHyper-VHost> | Move-VM–DestinationHost <Hyper-VHostName> -DestinationStoragePath E:\MyVM1
These PowerShell commands are used to live-migrate Hyper-V VMs operating outside the failover cluster. If you need to live-migrate Hyper-V VMs from one node to another node in a cluster, use the Move-ClusterVirtualMachineRole PowerShell cmdlet as shown below:
Get-VM <SQLVM> | Move-ClusterVirtualMachineRole -MigrationType Live -Node <NodeName> -Wait 0
And to live-migrate multiple Hyper-V VMs in a failover cluster, use the following PowerShell command:
Get-VM | Move-ClusterVirtualMachineRole -MigrationType Live -Node <NodeName> -Wait 0
The -Wait 0 parameter above specifies that the PowerShell cmdlet runs and then returns to the PowerShell prompt without waiting.
Dig Deeper on IT systems management and monitoring
Related Q&A from Nirmal Sharma
Use System Center Virtual Machine Manager and PowerShell to make logical network management easy. Execute a script to display network virtualization ... Continue Reading
Hyper-V replication is easy to use, but there are a number of steps you should take during Hyper-V replication setup to ensure you stay abreast of ... Continue Reading
Manage Hyper-V clusters more easily with PowerShell cmdlets and scripts that automate the retrieval and display of node information, including node ... Continue Reading