Powershell script to Live Migrate Hyper-V Virtual Machines to another Node in a Hyper-V 2008 R2 Cluster on a planned Host Shutdown

by Stan Czerno July 21, 2011 18:09 CST

On a planned or gracefull Hyper-V Host Shutdown, Live Migrate VMs to another Node in the Cluster. This Script is designed to work with a Two-Node Cluster.

You need to configure Group Policy or the Local Policy for the host to have a Shutdown Script. You'll find these settings under Computer Settings > Windows Settings > Scripts (Startup/Shutdown).

Using the PowerShell Scripts tab, set PowerShell scripts to run First so that the live migrations are performed before shutdown.

Let me know what you think about the script and if you have a better way of doing this.

http://www.czerno.com/default.asp?inc=/html/windows/hyperv/cluster/HyperV_Live_Migrate_VMs.asp

Windows Server 2012 NOTE: If you are using Windows Server 2012 or Hyper-V Server 2012 you will need to make a change in the registry to make this work. Open regedit, then navigate to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control. Modify PreshutdownOrder and remove vmms.

Speaking of Windows Server 2012, you do not even need to use this script. Windows Server 2012 includes new Powershell cmdlets and cmdlet features. Below is all you need for a script in a Windows Server 2012 Cluster, regardless of how many Nodes:

##Get this Node's Name
$Computer = Get-Content env:ComputerName

##Suspend this Node so nothing gets migrated to it 
write-host "This computer: " $Computer

write-host

Write-Host "Suspending Cluster Node and Draining VMs"
Suspend-ClusterNode $Computer -drain -wait

Tags: , , , ,

Catergories: Windows | HyperV | Powershell

Comments (3) -

mbrayez United States
February 23, 2012 08:34 CST

many thanks for your powerfull scripts,
but if i had some VMs that i dont want them to LM, what i had to add to the script
thanks in advance

regards

Reply

Stan Czerno United States
February 23, 2012 08:42 CST

If you have VMs you do not want to Live Migrate then I suppose the easiest thing to do would be to not include them in the Cluster.

Reply

Stan Czerno United States
November 5, 2012 11:55 CST

Be sure to understand the Priority impacts on Windows Server 2012 as noted here: http://www.aidanfinn.com/?p=13715

Reply

Add comment