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, pull and balance resources in a 2 or more node active / passive or active / active cluster.

About the Script

The purpose of the PowerShell script is to allow three 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. Last option is for active / active clusters called balance, this will move the resource to the preferred owner. 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, 2012 R2 and 2016 versions.

To achieve this we will create three functions and also set a string parameter to look for drain, pullall or balance 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. Please specify the URL of your file


So we have the script, how do we run it and what does it look like?  By running ClusterResourceMover2 drain or ClusterResourceMover2 pullall  or ClusterResourceMover2.ps1 balance 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 / 2016 clusters and also log operations for tracking.

3 Responses to “Using PowerShell to Failover Cluster Resources for Patching”

  1. Scott Buzbee says:

    Great script. Have you completed the balance portion of this script yet?

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.