As it’s looking increasingly likely I’ll be deploying Windows Failover Clustering, as a HA solution at work, I thought it would be prudent to swot up on a little related Powershell. I’ve picked out a few clustering cmdlets that will be helpful for building scripts to manage and monitor a cluster.

First things first!

If you leap in a little too quickly, like me, you may encounter the following error;

“The term ‘Get-Cluster’ is not recognized as the name of a cmdlet, function, script file or operable program.”

For some reason the Getting Started with Powershell on a Failover Cluster page isn’t as explicit about the need to do this as it should be; You need to import the module for clustering into the Powershell session.

Import-Module FailoverClusters;

Execute this command in your console session, or add it to the top of your script file, to make the Failover clustering commands available for use.

The Get-Cluster cmdlet

This cmdlet gets information about clusters. To get the names of all the cluster in a domain we simply execute;
Get-Cluster;

Windows Powershell command to list clusters in a domain

We use the same command, with Format-List,  to get further details of a specific cluster.

Get-Cluster -Name "CLUSTER" | Format-List *;

WIndows Powershell showing Failover Cluster details

Listing Cluster Nodes with Get-ClusterNode

This cmdlet allows us to list the nodes in the given cluster.

Get-ClusterNode -Cluster "CLUSTER";

Get-ClusterNode

We can get a little more detail on our node by using the Format-List cmdlet;

Get-ClusterNode -Cluster "CLUSTER" | Format-List *;

Failover Cluster Node Details

This shows us a few details about each node in the cluster including its State (i.e. if the node is up or down).

List the Resource Groups in a Failover Cluster

Using the Get-ClusterGroup cmdlet we can list the resource groups setup in a specific cluster.

Get-ClusterGroup -Cluster "CLUSTER";

Cluster Groups

Moving a Resource Group in a Failover Cluster

Sooner or later we’re going to want to perform maintenance on a server that requires moving the resource groups onto another node. Cluster resource group can be easily moved with the Move-ClusterGroup cmdlet. The next command will failover the a resource group called “ClusterDTC”

Move-ClusterGroup -Cluster "CLUSTER" -Name "ClusterDTC";

Where does this failover to? The documentation states that this method will failover a resource “from the current owner node to any other node” . This is fine if you’ve only got a two node cluster but sometimes you may wish to be explicit. The next command achieves the same as the last but states the node to move the resource group to.

Move-ClusterGroup -Cluster "CLUSTER" -Name "ClusterDTC" -Node "Node2";

The next sequence of commands shows how you might move resources in a simple two node failover cluster.

Get-ClusterGroup -Cluster "CLUSTER";
Move-ClusterGroup -Cluster "CLUSTER" -Name "ClusterDTC";
Move-ClusterGroup -Cluster "CLUSTER" -Name "SQL Server (MSSQLSERVER)";
Move-ClusterGroup -Cluster "CLUSTER" -Name "Cluster Group";
Move-ClusterGroup -Cluster "CLUSTER" -Name "Available Storage";
Get-ClusterGroup -Cluster "CLUSTER";

Moving Cluster Resource Groups with Powershell

List the Resources in a Failover Cluster

A cluster resource can be an application, service, storage, IP address or network name. To list the resources configured in your cluster execute the next command;
Get-ClusterResource -Cluster "CLUSTER" | Format-Table -Autosize;

The cmdlet will output all of the resources in the cluster with their state and a few other details,

Resources in a Failover Cluster via Powershell

Testing your Failover cluster

If you’ve setup a cluster then you would have used the wizard to validate the cluster configuration and setup. We can do the same thing in Powershell with the Test-Cluster cmdlet.

Test-Cluster -Cluster "CLUSTER";

The cmdlet will display a progress bar during the test.

Test-Cluster Powershell cmdlet

The cmdlet will take a few minutes to run depending on the number of Nodes in your cluster. The results will be displayed in the console once the cluster tests have completed. Some of the warnings here are due to me having a few services running at the time of the test. A full html report is generated which contains full details.

Test-Cluster Results

I’ll probably run this cmdlet periodically and email the generated html report so I can keep an eye on my cluster. Obviously judging by the output above I have a few thing to sort out on my test cluster!

I’ve quickly ran through a few of the cmdlets available for Windows Failover Clustering. There’s over sixty related Powershell cmdlets available for everything from setup, failover, monitoring and management of Windows Failover Clusters. Be sure to checkout the rest.