Recently the need arose to monitor the status of a Microsoft NLB cluster. There are a number of ways of approaching this, but PowerShell seemed like the cleanest.
I found this script on TechNet but found that it did not work in our (2008 R2) environment. During troubleshooting, what I found was that instead of returning a single status result, the WMI query was returning an array of results for each server. It appears that the statuscode is only relevant for the specific hostpriority applicable to each server.
For instance, this is the server with hostpriority 1 as shown in the NLB Manager:
And this is the one with hostpriority 2:
As you can see, a proper statuscode is only returned for the current hostpriority for each server.
With that in mind I made a change to the script to enumerate through the array of results for each server and check the status accordingly. This has only been tested on ADFS 2.0 on 2008 R2 servers, and it would need to be revised if you have more than two servers in a NLB cluster.
#Define Nodes $node1 = "SERVER01" $node2 = "SERVER02" #get NLB status on NLB Nodes $Node1status = Get-WmiObject -Class MicrosoftNLB_Node -computername $node1 -namespace root\MicrosoftNLB | Select-Object __Server, statuscode, status, hostpriority $Node2status = Get-WmiObject -Class MicrosoftNLB_Node -computername $node2 -namespace root\MicrosoftNLB | Select-Object __Server, statuscode, status, hostpriority $node1converged = $false Foreach ($status in $Node1status) { if(($status.hostpriority -eq "1" -and $status.statuscode -eq "1008") -or ($status.hostpriority -eq "2" -and $status.statuscode -eq "1007")) { $node1converged = $true write-host "NLB Status of $node1 is: Converged" } } Foreach ($status in $Node2status) { if(($status.hostpriority -eq "1" -and $status.statuscode -eq "1008") -or ($status.hostpriority -eq "2" -and $status.statuscode -eq "1007")) { $node2converged = $true write-host "NLB Status of $node2 is: Converged" } }
Sorry about the indents; they show up in the WordPress editor but not on the actual page.
Let me know if you find this useful, or if you are able to use it on a platform other than 2008 R2.