Hyper-V cluster host maintenance, mass live migration of virtual machines

If you have Hyper-V running on Windows Server 2008 R2 in a cluster, there are times when you will need to live migrate all virtual machine guests to another host for scheduled planned maintenance on a specific host. You can live migrate all virtual machines one by one, one after the other from one host to another host by automatically running the following PowerShell script:

Import-Module failoverclusters
get-cluster "$CL" | Get-Clusternode "$SH" | Get-ClusterGroup | Move-ClusterVirtualMachineRole -node "$DH"

As an example: get-cluster "dc-au-hvc-03" | Get-Clusternode "dc-au-hv-12" | Get-ClusterGroup | Move-ClusterVirtualMachineRole -node dc-au-hv-13

If you want to live migrate one specific virtual machine from one node to another:

get-cluster "$CL"| Move-ClusterVirtualMachineRole -name "SCVMM $VM Resources" -node "$DH"

Computers and Internet Uncategorized

3 Comments Leave a comment

  1. hi, what if i have 2 selected VMs and due to some reason, i must ensure the 2 Vms must always in the same hosts ( i form 8 nodes into cluster), how to write the powershell script? I will put a task scheduler to check daily twice if these 2 VMs are in the same host or not. If yes, do nothing ; else live-migrate the 2 VMs to the current largest capacity host. TQ

    • You should be able to set this in the properties of the VMs. Un-check persistent mode, and only select the Hosts that you want the VM to be on. This is what we have done here and the VMs tend to stay on the hosts we want them on.

      • thank you, but this method has some limitation; if the one of the preferred owner is down, then it will still fail over to another different host. besides that, if let say i choose A,B,C as the preferred owner, when i do the maintenance work on the host, i live migrate all the VM out, it is not intelligence enough to move to same host. that’s why i wish to have a powershell script with task scheduler to check daily if on the same host; else live migrate.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: