Configuring and Managing Hyper-V Live Migration with Powershell

Expected and unexpected downtime are necessary evils within the data center. Application upgrades, system patch windows and unexpected failures continue to challenge the IT Professional daily. What happens when the storage administrator updates the array the production VMs live on? Fortunately technologies built-in to Hyper-V help alleviate these problems. Both Live Migration and Live Storage Migration are to the rescue!

  • Live Migration – Moves the CPU and Memory state of the virtual machine from one host to another host.
  • Live Storage Migration – Moves VM hard disk files (VHD / VHDX, Checkpoint)

 

By default Hyper-V 2012 R2 sets the migration settings to allow 2 simultaneous migrations on an individual host. Environments are scaling larger and larger daily, Failover Cluster Manager allows 64 Hyper-V nodes to operate uniformly within a single namespace along with 8,000 VMs. When maintenance comes calling, simply right click on the Hyper-V node and choose Pause and then Drain Roles. This will queue all Live Migrations and begin to evacuate the VMs running on Host1 to other hosts in the Cluster automatically

You can manually migrate VMs from host to host also, but the limit of 2 simultaneous can become a challenge (See Figure 1).

2015-10-03_14-40-45

Figure 1: Error received when greater than 2 Live Migrations were attempted at once.


Powershell makes setting the Live Migration settings very easy, especially whenever you’re using Virtual Machine Manager (VMM). Simply make the necessary changes within the VMM GUI then choose View Script (See Figure 2). Now you have the necessary Powershell to make the requested changes, copy to your favorite Powershell editor (Powershell ISE or PowerGUI from Dell/Quest).  

2015-10-04_22-36-32

Figure 2: VMM, View Script and Powershell output

Powershell is an option to make mass changes or even place multiple hosts as part of a cluster within their respective maintenance modes and evacuate the running VMs off of those hosts. You can also leverage VMM and Failover Cluster Manager to Move Virtual Machine Storage and again, if you’re not a scripting expert, grab the Powershell and edit to fit the larger environment.