Windows Management and Scripting

A wealth of tutorials Windows Operating Systems SQL Server and Azure

Posts Tagged ‘live migration’

SCVMM PowerShell cmdlets can improve Hyper-V Live Migrations

Posted by Alin D on November 14, 2012

For small IT shops, PowerShell cmdlets improve on Hyper-V Live Migration functionality. But, with the addition of System Center Virtual Machine Manager and its PowerShell capabilities, those shops can precisely coordinate live migrations between nodes and Cluster Shared Volumes.

Microsoft System Center Virtual Machine Manager (SCVMM) includes a robust graphical user interface (GUI) from which administrators can perform Hyper-V live migrations. Even so, you may feel that SCVMM lacks the granular control needed to administer a complex, Hyper-V virtual infrastructure.

SCVMM PowerShell cmdlets, however, provide increased flexibility when managing Live Migration, far beyond what is possible with the GUI. With the following SCVMM PowerShell cmdlets and scripts, for example, you can live migrate an entire host’s worth of virtual machines (VMs) to a specific node, or transfer VMs based on their Cluster Shared Volumes assignments.

(Note: You must install the SCVMM console on the server or workstation from which you are running the script.)

Migrating all VMs from one node to another

Maintenance Mode is an SCVMM feature found within the graphical console that uses an Intelligent Placement algorithm to distribute all the VMs from the node of your choice to the remaining nodes in the cluster. But what if you want to maintain the same combination of VMs, just on a different node?

For example, in my virtual infrastructure, I have a mix of load balanced applications within a cluster. Placing load-balanced VM workloads on the same cluster node limits the effectiveness of the load balancing, especially in the event that a host fails.

Also, by maintaining the same mix of VMs on the destination node, you already know what the resource load will be. From my experience, even with a full free node in the cluster, SCVMM’s Maintenance Mode does not always move every source node VM to the empty destination node. That’s because the SCVMM Intelligent Placement feature constantly gathers load characteristics from each host to determine the best placement of VMs. As the free node receives additional VMs, its placement score goes down, causing SCVMM to distribute the remaining VMs to other cluster nodes.

From the GUI, there’s only one way to force the live migration of every VM on a node to another, named node: by manually going through the migration wizard for each VM.  But the following script overrides Intelligent Placement and synchronously move the VMs to a specific cluster node, simply by answering a few prompts.

# ——————————————————————————
# Migrate All VMs to Alternate Node in the Same Cluster
# ——————————————————————————

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

$VMM = Read-Host “Enter Name of VMM Server”
$SH = Read-Host “Enter Source Host Name”
$DH = Read-Host “Enter Destination Host Name”

Get-VMMServer -computername $VMM
Get-VM | ? {$_.hostname -like “$SH*”} | Move-VM -VMHost “$DH*”

To run the script, follow these steps:

  1. Save the SCVMM PowerShell script above (e.g., MigrateAllVMsOnNode_SCVMM.ps1)
  2. Open Windows PowerShell.
  3. Run the script.
  4. Answer the prompts for SCVMM server, source node name and a destination node within the same cluster.Migrate All VMs On Node
  5. Follow progress of the migration from the command status, Failover Cluster Manager or the SCVMM Jobs page.

Check Status on Console

Migrating VMs on a Cluster Shared Volume between nodes

This script identifies the VMs on a particular Cluster Shared Volume, and live migrates them to a specified destination node. Use this script to keep VMs on a Cluster Shared Volume together on the same host after a live migration.

Hyper-V Cluster

Why would you want to do this? During normal cluster operations, a VM resource can utilize direct I/O from a volume shared between all nodes, and any node in the cluster can own that VM resource. But problems arise if you use Microsoft Data Protection Manager or other backup software based on Hyper-V Volume Shadow Copy (VSS).  During a backup, only the node that owns the VM’s CSV has direct access to disk I/O. VMs that live on other nodes but share the same CSV will have their I/O redirected over the network, causing disk latency and degraded performance.

To avoid this issue, enact the following placement architecture to maintain full disk I/O with no deprecated performance for all VMs on that CSV volume. To reorganize VMs after using Maintenance Mode, use this script to easily live migrate just the VMs on a particular CSV to the desired source node.

 

# ——————————————————————————
# Live Migrate Virtual Machines On a Particular Volume to a New Host in Same Cluster
# ——————————————————————————

Add-PSSnapin Microsoft.SystemCenter.VirtualMachineManager

$VMM = Read-Host “Enter Name of VMM Server”
$SH = Read-Host “Enter Source Host Name”
$DH = Read-Host “Enter Destination Host Name”
$Vol = Read-Host “Enter Volume/CSV Volume to Move VMs to Destination Host”

Get-VMMServer -computername $VMM
Get-VM | ? {$_.hostname -like “$SH*”} | ? {$_.Location -like “*$Vol*”} | Move-VM -VMHost “$DH*”

  1. Save the PowerShell script above (e.g. MigrateAllVMsByVolume_SCVMM.ps1).
  2. Open Windows PowerShell.
  3. Run the script that you saved above.
  4. Answer the prompts for SCVMM server, source node name, destination node and the Cluster Shared Volume of VMs that you want to target.
  5. Follow progress of the migration from the command status, Failover Cluster Manager or the SCVMM Jobs page.

Further experimentations with SCVMM PowerShell cmdlets
The above scripts are just two examples of what you can do with the SCVMM PowerShell cmdlets. Because of the depth of information that SCVMM gathers about each VM, there are more ways to include or exclude VMs for Live Migration:

  • Name: You can live migrate VMs with a certain name attribute (e.g., using the <tt>–like</tt>command option).
  • Memory:  You can target VMs that are above or below a certain memory threshold.
  • Operating system:  You can select virtual machines by operating system, such as Windows, Linux (quick migration only), etc.

Conclusion

With SCVMM PowerShell cmdlets, you can customize your Live Migration experience far beyond what’s possible in the graphical console. System Center Virtual Machine Manager 2012 will add options within its updated cmdlet, but the GUI will still lack granular management functionality. As such,  it is in your best interest to learn how to streamline administrative tasks with SCVMM PowerShell cmdlets.

About these ads

Posted in System Center | Tagged: , , | Leave a Comment »

 
Follow

Get every new post delivered to your Inbox.

Join 270 other followers

%d bloggers like this: