3

We need a way to determine from code which node of an application cluster is currently active. Is there a way to do this using C#?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Nancy A
  • 33
  • 1
  • 3

1 Answers1

0

This isn't C# code, it's PowerShell. So, it's not an answer, but I needed a PowerShell solution to get the nodes in general (not necessarily the active node) and this question came up in my Google search. IMO, the PowerShell FailoverClusters module is rather poorly written, so I have to revert to (mostly) non-PowerShell objects (like WMI) to get it done right.

$Clusters=Get-ADComputer -Server "<specific domain controller (optional)" -LDAPFilter "(servicePrincipalName=*MSClusterVirtualServer/*)" -SearchBase "OU=Servers,DC=<domain name>,DC=com" | Select-Object -ExpandProperty DNSHostName
$ClusterNodes=$Clusters | ForEach-Object { Get-WMIObject -Namespace "root\MSCluster" -ComputerName $_ -Query "SELECT Name FROM MSCluster_Node" -EnableAllPrivileges } | Select-Object -ExpandProperty Name