Using PowerShell to Failover Cluster Resources for Patching


So you are having to patch cluster nodes and would like a way to automate the failover of the resources and log what when it was done and who did the work. In this post we will cover a simple PowerShell script that will drain and pull resources in a 2 node active / passive cluster.

About the Script

The purpose of the PowerShell script is to allow two operations to occur, they are to drain all the resources on the node you are running the script on to the other node in the two node cluster and the other is to bring all (pullall) the resources from a node to the node. While doing this to also create a local log file  and also to create a Event in the Application event log. Using this script you can automate patching of clusters with SCCM and other methods. Another note is that the script be able to work on Windows Server 2008, 2008 R2, 2012 and 2012 R2 versions.

To achieve this we will create two functions and also set a string parameter to look for drain and pullall at the PowerShell command line. For the PowerShell cluster operations we will be using the FailOverClusters module and several get cmdlets such as Get-ClusterGroup, Get-ClusterResource, Move-ClusterGroup and Get-ClusterNode.

For the logging events portion we will be capturing who is doing the failover, the date and time and what operation is performed into the local logfile stored in c:\support directory using Out-File and Add-Content cmdlets. For the Event logging we will use the Write-EventLog cmdlet and create the event in Application Log. Below is the script and is fairly easy to read and can be modified to your liking. In a future post we will add the balance feature to allow this script to be used to send Cluster Groups to preferred owners in Active / Active clusters and some error checking.

The Script

Here is the script in it’s entirety. Download Now


So we have the script, how do we run it and what does it look like?  By running ClusterResourceMover2 drain or ClusterResourceMover2 pullall we can make the script do its magic.



So we see it is possible to use the FailoverClusters PowerShell module to automate patching of Windows Servers 2008 / 2012 clusters and also log operations for tracking. Stay tuned for more features being added to this script!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.