Powershell – Get the Cluster Owning node name using powershell

clusterpowershell

Cluster Resource "Cluster Disk" fetching the data

Listing status for resource 'SQL Server (CLUSTER)':

Resource Group Node Status


Cluster Disk Cluster Disk Node1 Online

How can i parse the Node name here or is there some other command which would help me fetch it?

Best Answer

Windows Server 2008 R2 and higher include a Powershell module for failover clusters, however they are not backward compatible with Windows Server 2008 or 2003. I prefer to use WMI which supports all OS versions and does not require parsing. Here's how to list resources and active node using WMI:

 $cluster = "myCluster"
 gwmi -ComputerName $cluster -Authentication PacketPrivacy -Namespace "root\mscluster" -Class MSCluster_Resource |
  add-member -pass NoteProperty Cluster $cluster | 
    add-member -pass ScriptProperty Node {
     gwmi -namespace "root\mscluster" -computerName $this.Cluster -Authentication PacketPrivacy -query "ASSOCIATORS OF {MSCluster_Resource.Name='$($this.Name)'} WHERE AssocClass = MSCluster_NodeToActiveResource" |
      Select -ExpandProperty Name } | select name, node
Related Topic