Script to evacuate cluster node on shutdown

Script to evacuate cluster node on shutdown

  • Comments 8


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:

http://pdconsec.net/blogs/davidr/archive/2010/09/01/Automatically-Live-Migrate-VMs-On-Host-Shutdown.aspx

Cheers,
Ben

Leave a Comment
  • Please add 5 and 4 and type the answer here:
  • Post
  • What happens when a shutdown force command is executed? ie: shutdown /f Does the script still run?

  • I would assume not - but I need to confirm that.

  • 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 :)

  • David -

    Thanks for the extra info!

    Cheers,

    Ben

  • 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" }))

  • 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:\Tasks\AutomaticStartAction\HyperV.psd1 } -session $session

    Invoke-command { set-vm vm1 -autostart 2 } -session $session

    Invoke-command { set-vm vm2 -autostart 2 } -session $session

  • Correction:

    $session = New-PSSession -computerName hypervnode1

    Invoke-command { import-module C:\Tasks\AutomaticStartAction\HyperV.psd1 } -session $session

    Invoke-command { set-vm vm1 -autostart 2 } -session $session

    Invoke-command { set-vm vm2 -autostart 2 } -session $session

  • Looks like this link is dead. Anyone still have the article or script?

Page 1 of 1 (8 items)