I wanted to find a way of programatically identifying the active node of a SQL Server Cluster. I found this post that demonstrated how to do it with TSQL. As I love Powershell so much here’s another method to do it;

# Set cluster name
$cluster_name = "ClusterName";
# Load SMO extension
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SqlServer.Smo") | out-null;
$srv = New-Object "Microsoft.SqlServer.Management.Smo.Server" $cluster_name;
# Get server properties
$properties = $srv.Properties
$owner_node = $properties.Item("ComputerNamePhysicalNetBIOS").Value;
$is_clustered = $properties.Item("IsClustered").Value
	Write-Host "The current active node of $cluster_name is $owner_node.";
	Write-Host "$cluster_name is not a clustered instance of SQL Server.";

Execute against your cluster and it will tell you which is the current active node.

The current active node of ClusterName is Node1.

It will also tell you if the instance you’re executing against isn’t a cluster.

NotACluster is not a clustered instance of SQL Server.