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#?
Asked
Active
Viewed 6,844 times
3
-
possible duplicate of [SQL Server failover cluster - determine active node](http://stackoverflow.com/questions/4491411/sql-server-failover-cluster-determine-active-node) – bzlm Dec 20 '10 at 20:54
-
This is a non-SQL cluster. I need a way to determine the currently active node on an application cluster. Anyone have a way to do that? – Nancy A Jan 31 '11 at 21:32
-
Pretty vague question. What application cluster are you talking about? – Daniel Hilgarth Feb 23 '11 at 10:00
-
did you use Windows Server 2012 R2 ? – PreguntonCojoneroCabrón Sep 20 '18 at 20:25
1 Answers
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

Slogmeister Extraordinaire
- 2,890
- 2
- 25
- 39