Essential Guide

Live Migration vs. vMotion: A guide to VM migration

A comprehensive collection of articles, videos and more, hand-picked by our editors

Overcoming Hyper-V Live Migration limitations with PowerShell cmdlets

Hyper-V Live Migration still has a few shortcomings, but these Windows PowerShell cmdlets can help you get around them.

With Windows Server 2008 R2, Microsoft lessened the feature gap between Hyper-V’s Live Migration and competitors’,

but it still has some limitations. Thankfully, you can work around the shortcomings in Hyper-V Live Migration using Windows PowerShell cmdlets.

Hyper-V Live Migration allows admins to move a  virtual machine (VM) from one Hyper-V cluster node to another with no noticeable downtime. Some shortcomings that remain, however, include the inability to live migrate multiple VMs at one time, the lack of scheduling capabilities for live migration, and the inability to migrate VMs based on specific criteria. Hyper-V 3.0, slated for some time in 2012, promises to improve on Hyper-V Live Migration’s limitations, but for now, there are viable workarounds with the help of PowerShell cmdlets.

Using the PowerShell Failover Cluster cmdlet
Most large Hyper-V clustered installations implement System Center Virtual Machine Manager (SCVMM), but for organizations with only one or a few Hyper-V clusters, PowerShell cmdlets can automate and orchestrate the live migration process, while avoiding the additional cost of SCVMM. Most Windows cluster administrators are familiar with Cluster.exe for managing cluster resources, but the PowerShell Failover Cluster cmdlet can accomplish even more live migration functions.

Migrating a single VM to another node in the same cluster
The following PowerShell script gives you the flexibility to migrate any VM independent of what cluster it’s in -- all right from your desktop. All you need to know is the name of the cluster alias, the exact name of the clustered VM resource, and the destination node where you want to migrate your VM . You could also modify this script to schedule the live migration of one or multiple VMs, allowing you to automate live migration in preparation for node maintenance.

One thing you should know is that if you want to migrate VMs from a Windows 7 desktop, you must have the Remote Server Administration Tools (RSAT) installed and the Failover Cluster feature enabled. RSAT is already available for servers that have clustering enabled.

Here is the PowerShell script you can use to live migrate a single VM within a cluster:

# ------------------------------------------------------------------------------
# Migrate Single Virtual Machine With Failover Cluster CMDLet
# ------------------------------------------------------------------------------
# Necessary to enable failover cluster functions
 Import-Module FailoverClusters

$CL = Read-Host "Enter Cluster Alias Name"
$VM = Read-Host "Enter Full Cluster Name Resource Name of VM to Migrate"
$DH = Read-Host "Enter Destination Host Name"

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

Make sure the VM you want to migrate is turned on (or else you’ll get an error), and follow these steps to run the PowerShell script:

  1. Save the PowerShell script above. (For example, MigrateSingleVM.ps1)
  2. Open Windows PowerShell.
  3. Run the script that you saved above.
  4. Answer the prompts for Cluster Alias, Clustered VM Resource Name and a Destination node within the same cluster.

  5. Figure 1
    Answer these prompts for the cluster details. (Click image for an enlarged view.)
  6. Follow the live migration’s progress from the command status or with Failover Cluster Manager.


Figure 2
You can follow the live migration progress. (Click image for an enlarged view.)
 

Migrating all VMs from one node to another in the same cluster
For maintenance tasks on a particular host, you may want to perform a live migration that moves all VMs from one host to another host in the same cluster. Instead of using Hyper-V Live Migration, you can use PowerShell cmdlets to manually run the prompt, or modify it slightly so it can be used in preparation for a maintenance event or even as a response to a predictive node failure. Since Hyper-V Live Migration can only migrate one server at a time, this PowerShell script is a huge time saver.

Here’s the PowerShell script to live migrate multiple VMs simultaneously:

# ------------------------------------------------------------------------------
# Migrate All Virtual Machines on One Node to Another with Failover Cluster CMDLet
# ------------------------------------------------------------------------------
# Necessary to enable failover cluster functions

Import-Module FailoverClusters

$CL = Read-Host "Enter Cluster Alias Name"
$SH = Read-Host "Enter Source Host Name"
$DH = Read-Host "Enter Destination Host Name"

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

To run the script, follow the same steps you did when migrating a single VM. Save the PowerShell script, run it and make sure to answer all the prompts.

As you can see, the Failover Cluster PowerShell cmdlet is very powerful and can be modified to accomplish tasks you can’t do with Hyper-V Live Migration. Add your own live migration shortcuts to the comments section at VirtuallyAware.com.

This was first published in November 2011

Pro+

Features

Enjoy the benefits of Pro+ membership, learn more and join.

Essential Guide

Live Migration vs. vMotion: A guide to VM migration

2 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchVMware

SearchWindowsServer

SearchCloudComputing

SearchVirtualDesktop

SearchDataCenter

Close