Get the active node of an Exchange 2007 CCR cluster using PowerShell…

Posted by in Exchange, PowerShell

There’s not a massively easy way of checking for the active node of a cluster without manually going into Failover Clustering or into the properties of the cluster in the EMC. Get-ClusteredMailboxServerStatus will give you the active node by getting the OperationalMachines attribute but if you’d like to use this in scripts or display it in a nice format then it’s not in the most helpful format (it’s an array). It usually looks something like this:

{NODE1, NODE2 <Active, Quorum Owner>}

Using the following script we can retrieve all the clustered servers, then run Get-ClusteredMailboxServerStatus on each one and extract the active node from OperationalMachines attribute based on whether “Active” exists in the array.

NB. This must be run on a machine that has failover clustering feature installed (so, one of the nodes probably) – that’s the only annoying thing.

Here’s the code:

$Clusters = Get-MailboxServer | ? {$_.ClusteredStorageType -ne "Disabled"}
ForEach ($Cluster in $Clusters) {
   $ClusterStatus = Get-ClusteredMailboxServerStatus -Identity $Cluster.Name | Select -Expand OperationalMachines | ForEach {If($_ -like "*Active*") {$_}}
   $ActiveNode = $ClusterStatus.Split(" ")[0]
   Write $ActiveNode