Powershell - Getting Cluster information

rated by 0 users
This post has 0 Replies | 1 Follower

Top 75 Contributor
Posts 25
willsteele Posted: 11-18-2009 1:15 PM

I work regularly with clustered servers and often need to know which machine is the active node.  I have used wmic to get this information before, but, prefer to automate this rather than use a .bat file or the cmd shell.  I found a nice way to approach this using powershell.  To get information about the active node by authenticating use this script.  Note the generic parameters must be set for your -computername and -Credential parameters with actual values.

gwmi -q "Select * from mscluster_nodetoactivegroup" -namespace root\mscluster -computername "192.168.0.10" -Credential "Domain\User" -Authentication 3

Be aware it is normal for Windows to prompt you to authenticate with a standard password dialog box as a result of Kerberos.  This points to the fact that no password was entered into the script, so, it is somewhat secure.  If you do not include the -Credential switch in the script (whether as a parameter or a hard-coded value) it will error because you autenticate by default as the local machine.  The error you will see is:

Get-WmiObject : Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
At line:1 char:5
+ gwmi <<<<  -Query "select * from mscluster_nodetoactivegroup" -namespace root\mscluster -computername "192.168.0.10"
-Authentication 3
    + CategoryInfo          : NotSpecified: (:) [Get-WmiObject], UnauthorizedAccessException
    + FullyQualifiedErrorId : System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.GetWmiObjectCommand

If you run the same query, without a user parameter, directly in wmic you will see the same error. The HRESULT 0x80070005 is a standard response returned by WMI when authenticate to a remote machine fails.

The results you will get are very verbose. To trim them down, I use the findstr command, but, I would imagine there is a better way to do it in Powershell.  I run this query (note the additional | Findstr filter:

gwmi -q "Select * from mscluster_nodetoactivegroup" -namespace root\mscluster -computername "192.168.0.10" -Credential "Domain\User" -Authentication 3 | findstr "SERVER"

And get these results:

__SERVER : MYREMOTESERVERNAME
__SERVER : MYREMOTESERVERNAME

Page 1 of 1 (1 items) | RSS
Copyright 2012 PowerShell.com. All rights reserved.