Script to evacuate cluster node on shutdown
A little while ago David posted a really handy solution for evacuating a Hyper-V cluster node on shutdown automatically.
The issue that he is trying to address is that normally you should not just shutdown a node in a cluster, rather you should manually move all virtual machines off of the cluster node first. If you just shutdown a node in a cluster all the virtual machines will be failed over using quick migration.
David solved this problem by writing a PowerShell script that works with clustering to live migrate the virtual machines to another node in the cluster. He then uses group policy to get this script to be run automatically whenever a computer in his cluster is shutdown.
All-in-all it is a really cool solution to make your life a little easier. You can read all about it here:
Cheers,
Ben
Comments
Anonymous
October 25, 2010
What happens when a shutdown force command is executed? ie: shutdown /f Does the script still run?Anonymous
October 26, 2010
I would assume not - but I need to confirm that.Anonymous
October 28, 2010
Yes, the shutdown script will still run if you force the host to reboot with shutdown /f - local policy and group policy shutdown scripts are executed during the shutdown sequence. The original driver for the script was so that patching of the host servers with SCCM could occur automatically during maintenance windows; the reboots occur after patching is complete. There's one server per maintenance window - so at the end of the process, all servers have roughly the same number of VMs and one server is "empty". Then, SCOM/SCVMM Pro Tips take over and balance out anything grievously bad. Thanks for the mention Ben :)Anonymous
November 01, 2010
David - Thanks for the extra info! Cheers, BenAnonymous
November 02, 2010
If you have a 2 node cluster, you get an error from trying to index an array when a single object is returned for available nodes. Casting the statement as an array fixes this: $AvailNodes = @((get-clusternode | Where-Object { $.State -eq "Up" -and $.Name -ne "$Computer" }))Anonymous
July 12, 2012
Since Automatic Start Action does not persist after a Live Migration I modified the previously provided code (currently not available), by using pshyperv.codeplex.com/.../38769 and adding at the end of script: Invoke-command { import-module C:TasksAutomaticStartActionHyperV.psd1 } -session $session Invoke-command { set-vm vm1 -autostart 2 } -session $session Invoke-command { set-vm vm2 -autostart 2 } -session $sessionAnonymous
July 12, 2012
Correction: $session = New-PSSession -computerName hypervnode1 Invoke-command { import-module C:TasksAutomaticStartActionHyperV.psd1 } -session $session Invoke-command { set-vm vm1 -autostart 2 } -session $session Invoke-command { set-vm vm2 -autostart 2 } -session $sessionAnonymous
August 16, 2012
Looks like this link is dead. Anyone still have the article or script?