Check Cluster Group

Microsoft.Windows.Cluster.HostedGroup.StateMonitoring.ErrorDiagnostic (Diagnostic)

Run a PowerShell Cmdlet to check the Cluster Group on Cluster.

Element properties:

TargetMicrosoft.Windows.Cluster.HostedGroup
MonitorMicrosoft.Windows.Cluster.HostedGroup.StateMonitoring
RemotableTrue
Timeout300
Execute On StateError
CategoryAvailabilityHealth
Enabledfalse
AccessibilityPublic

Member Modules:

ID Module Type TypeId RunAs 
DG ProbeAction System.CommandExecuterProbe Default

Source Code:

<Diagnostic ID="Microsoft.Windows.Cluster.HostedGroup.StateMonitoring.ErrorDiagnostic" Accessibility="Public" Enabled="false" Target="ClusLibrary!Microsoft.Windows.Cluster.HostedGroup" Monitor="Microsoft.Windows.Cluster.HostedGroup.StateMonitoring" ExecuteOnState="Error" Remotable="true" Timeout="300">
<Category>AvailabilityHealth</Category>
<ProbeAction ID="DG" TypeID="System!System.CommandExecuterProbe">
<ApplicationName>%SystemRoot%\system32\cmd.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>/c $file/Main.cmd$</CommandLine>
<TimeoutSeconds>360</TimeoutSeconds>
<RequireOutput>true</RequireOutput>
<Files>
<File>
<Name>Main.cmd</Name>
<Contents><Script>

@echo off

set psscript=ClusterGroupDiag.ps1
set vbscript=ClusterGroupDiag.js
set cscript=%windir%\system32\cscript.exe
set ps=%windir%\system32\WindowsPowerShell\v1.0\powershell.exe
set params=

if Exist "%cscript%" goto vb
if Exist "%ps%" goto pshell
goto end
:vb
if not exist "%~dp0%vbscript%" goto end

"%cscript%" /nologo "%~dp0%vbscript%"
goto end
:pshell
if not exist "%~dp0%psscript%" goto end

"%ps%" -nologo -EP bypass -command "&amp; '%~dp0%psscript%'"
goto end

:end



</Script></Contents>
<Unicode>false</Unicode>
</File>
<File>
<Name>ClusterGroupDiag.ps1</Name>
<Contents><Script>

function Get-CmdFilename([string]$fullname)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$fileparam = "psparams.txt"
$fullnameparams = ".\$fileparam"
$fullparams = [System.IO.Path]::GetFullPath($fullnameparams)
if (0 -ne $error.Count)
{
$error.Clear()
$fullparams = $fullnameparams
}

if ($false -eq [string]::IsNullOrEmpty($fullname))
{
$error.Clear()
$fullnameparams = [System.IO.Path]::GetDirectoryName($fullname)
if (0 -eq $error.Count)
{
$fullpath = [System.IO.Path]::Combine($fullnameparams,$fileparam)
if (0 -ne $error.Count)
{
$error.Clear()
$fullpath = $fullnameparams + "\" + $fileparam
}

$fullparams = $fullpath
}
}

$error.Clear()
$IsFlag = $null
$IsFlag = [System.IO.File]::Exists($fullparams)

if ($null -eq $IsFlag)
{
$error.Clear()
return $null
}

if ($false -eq $IsFlag )
{
$fullparams = $null
}

$error.Clear()

return $fullparams
}

Function Parse-Params([string]$Value)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

if ([string]::IsNullOrEmpty($Value))
{
return null
}

$i = $Value.IndexOf("=")
if (-1 -eq $i) { return $null; }

$i++;

$result = ""

if ($i -le $Value.Length )
{
$result = $Value.Substring($i)
}

return $result
}

Function Get-CmdParams([string]$fullname,[int]$MaxCount=0)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

if ($MaxCount -lt 0)
{
$MaxCount = 0
}

$filename = Get-CmdFilename -fullname $fullname

if ($null -eq $filename)
{
return $null
}

$ap = Get-Content -Path $filename -Force

if (0 -ne $error.Count)
{
return $null
}

if (0 -eq $ap.Length)
{
return $null
}

$result = @()
$i = 0
foreach($d in $ap)
{
$p = Parse-Params -Value $d
if ($null -ne $p)
{
$i++
if ($i -gt $MaxCount -and 0 -ne $MaxCount) { break; }
$result += $p
}
}

return $result
}

function Check-WmiMethod($oObject,[string]$MethodName,$useCim) #As Boolean
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$method = $null

if ([string]::IsNullOrEmpty($oObject))
{
return $NodeName
}


if($true -eq $useCim)
{
$method = $oObject | Get-Member -Name $MethodName -MemberType Method
}
else
{
$methods = $oObject.CimClass.CimClassMethods
if($null -ne $methods)
{
$method = $methods[$MethodName]
}
}

$result = ($null -ne $method -and 0 -eq $error.Count )

return $result;
}

Function CheckCimModule()
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$retval = $false
$cim = Get-Module -Name CimCmdlets

########Check for powershell 1.0
if ($error.Count -ne 0)
{
if ($null -eq $error[0].Exception)
{
return $retval
}

$type = $error[0].Exception.GetType()
if ([System.Management.Automation.CommandNotFoundException] -eq $type)
{
return $retval
}

$error.Clear()
}

if ($null -eq $cim)
{
Import-Module CimCmdLets
if ($error.Count -eq 0)
{
$retval = $true
}

$error.Clear()
}
else
{
$retval = $true
}

return $retval
}

function CheckCmdLets()
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$retval = $false
$objSWbemObjectSet =$null

if (CheckCimModule)
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$objSWbemObjectSet = Get-CimInstance -CimSession $cimsession -Class Win32_OperatingSystem
}
catch
{
$objSWbemObjectSet = Get-WMIObject -Class Win32_OperatingSystem
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -eq 0)
{
$retval = $true
}
}

$error.Clear()
return $retval;
}

function Check-CimInstance($oWmiInstance)
{
$result = $null

if([string]::IsNullOrEmpty($oWmiInstance))
{
return $result
}

$type = $oWmiInstance.GetType()
if([string]::IsNullOrEmpty($type))
{
return $result
}

$useCim = $type.Fullname -eq "Microsoft.Management.Infrastructure.CimInstance"
if ($true -eq $useCim)
{
return $useCim
}

$useCim = $type.Fullname -eq "System.Management.ManagementObject"
if ($true -eq $useCim)
{
$result = $false
}

return $result
}

Function Get-WmiEscapedName([string]$Name)
{
$Name = ($Name -replace "\\", "\\") -replace "'","\'"

return $Name
}

Function Get-WmiCimSession([string]$ComputerName)
{
$ErrorActionPreference = 'SilentlyContinue'
$Error.Clear()

$CimSession = = $null
$CimSession = = Get-CimSession -ComputerName $ComputerName

if ($null -eq $CimSession)
{
$Error.Clear()
$CimSession = New-CimSession -ComputerName $ComputerName
}
else
{
if ($CimSession.Count -gt 1)
{
$CimSession = $cims[0]
}

}

return $CimSession
}

Function Get-WmiCimAssociatorInstance
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sAssociatorName,
$oWmiInstance,
[string]$relatedClass,
[string]$Source,
[string]$Target,
$CimSession
)

$ErrorActionPreference = 'SilentlyContinue'
$Error.Clear()

$result = $null

if ([string]::IsNullOrEmpty($CimSession))
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
}
else
{
$type = $CimSession.GetType()
if ([string]::IsNullOrEmpty($type))
{
return $result
}

if ("Microsoft.Management.Infrastructure.CimSession" -ne $type.FullName)
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
}

}

if (0 -ne $Error.Count)
{
return $result
}
$result = $CimSession.EnumerateAssociatedInstances($sNamespace,$oWmiInstance,$sAssociatorName,$relatedClass,$Source,$Target)

return $result
}

Function Get-WmiAssociatorInstanceNoAbort
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sAssociatorName,
$oWmiInstance,
[string]$relatedClass,
[string]$Source,
[string]$Target,
$CimSession
)

$ErrorActionPreference = 'SilentlyContinue'
if ([string]::IsNullOrEmpty($ComputerName))
{
$ComputerName = "."
}

$Error.Clear()

$oInstance = $null
$result = @()

if([string]::IsNullOrEmpty($oWmiInstance))
{
return $result
}

$useCim = Check-CimInstance -oWmiInstance $oWmiInstance

if ($null -eq $useCim)
{
return $result
}

if ($true -eq $useCim)
{
$oInstance = Get-WmiCimAssociatorInstance -ComputerName $ComputerName -sNamespace $sNamespace -sAssociatorName $sAssociatorName -oWmiInstance $oWmiInstance -Source $Source -Target $Target -CimSession $CimSession
}
else
{
$oInstance = $oWmiInstance.GetRelated($relatedClass,$sAssociatorName,$null,$null,$Target,$Source,$null,$null)
}

if ($null -eq $oInstance)
{

return $null
}

$result += $oInstance

return $result
}

Function Get-WmiInstanceNoAbort
{
param (
[string]$ComputerName,
[string]$sNamespace,
[string]$sClassName,
[string]$sFilter,
[bool] $useCim
)

$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$KerberosErrorCode = 2147943712
$ConnectionErrorCode = 2147942453
$WmiConnectErrorCode = -2147023174

if ([string]::IsNullOrEmpty($ComputerName))
{
$ComputerName = "."
}

if ([string]::IsNullOrEmpty($sNamespace))
{
$sNamespace = "root\cimv2"
}

if ($true -eq $useCim)
{
$oInstance = $null
if ([string]::IsNullOrEmpty($sFilter))
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -ComputerName $ComputerName
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorData.Error_code
If ($KerberosErrorCode -eq $ErrorCode -or $ConnectionErrorCode -eq $ErrorCode)
{
$error.Clear()
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
}
}
else
{
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -ComputerName $ComputerName -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -ComputerName $ComputerName -Filter $sFilter
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorData.Error_code
If ($KerberosErrorCode -eq $ErrorCode -or $ConnectionErrorCode -eq $ErrorCode)
{
$error.Clear()
Load-CimModules
try
{
$cimSessionOption = New-CimSessionOption -Protocol DCOM
$cimsession = New-CimSession -SessionOption $cimSessionOption
$oInstance = Get-CimInstance -CimSession $cimsession -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
catch
{
$oInstance = Get-WMIObject -Namespace $sNamespace -ClassName $sClassName -Filter $sFilter
}
Finally
{
Get-CimSession | Remove-CimSession
$cimsession =$null
$cimSessionOption = $null
}
}
}

}
}
else
{
$oInstance = $null
if ([string]::IsNullOrEmpty($sFilter))
{
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -ComputerName $ComputerName
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorCode
If ($WmiConnectErrorCode -eq $ErrorCode)
{
$error.Clear()
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace
}
}
}
else
{
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -Filter $sFilter -ComputerName $ComputerName
if ($error.Count -ne 0)
{
$ErrorCode = $error[0].Exception.ErrorCode
If ($WmiConnectErrorCode -eq $ErrorCode)
{
$error.Clear()
$oInstance = Get-WmiObject -Class $sClassName -Namespace $sNamespace -Filter $sFilter
}
}

}
}

return $oInstance
}

Function ConvertNumericResourceStateToString($state)
{
if ($null -eq $state)
{
return "Unknown"
}

$States = @{[uint32]0 = "Inherited";[uint32]1 = "Initializing";[uint32]2 = "Online";[uint32]3 = "Offline";[uint32]4 = "Failed";[uint32]128 = "Pending";[uint32]129 = " Online Pending";[uint32]130 = "Offline Pending"}
$textualState = $States[$state]

if ($null -eq $textualState)
{
$textualState = "Unknown"
}

return $textualState;
}

Function ConvertNumericResourceGroupStateToString($state)
{
if ($null -eq $state)
{
return "Unknown"
}

$States = @{[uint32]0 = "Online";[uint32]1 = "Offline";[uint32]2 = "Failed";[uint32]3 = "Partially Online";[uint32]4 = "Pending"}
$textualState = $States[$state]

if ($null -eq $textualState)
{
$textualState = "Unknown"
}

return $textualState;
}


Function Load-CimModules
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$CimModule = Get-Module CimCmdlets

if ($null -eq $CimModule)
{
Import-Module CimCmdlets
$error.Clear()

}
}


#==========================================================================
# FUNCTIONS
#==========================================================================
function Main()
{

if([string]::IsNullOrEmpty($GroupName))
{
Write-Host "Group name is empty."
return
}

if ([string] -ne $GroupName.GetType())
{
Write-Host "Group name is empty."
return
}

if ([string]::IsNullOrEmpty($GroupName.Trim()))
{
Write-Host "Group name is empty."
return
}

$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$useCim = CheckCmdLets

If ($null -eq $useCim)
{
Write-Host "Cannot get wmi cmdlets version."
return
}

$oGroup = Get-ClusterGroup -useCim $useCim -GroupName $GroupName

if(0 -ne $error.Count)
{
$e = $error[0].Exception.Message
Write-Host "Cannot get cluster group from wmi. Error: $e"
return
}

if ($null -eq $oGroup)
{
Write-Host "Cluster resource group $GroupName is not found."
return

}

Get-Resources -oGroup $oGroup

}

Function Get-ClusterGroup([string]$GroupName,$useCim)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$NameSpace = "root\mscluster"
$ClassName = "MSCluster_ResourceGroup"
$EscapeGroupName = Get-WmiEscapedName -Name $GroupName
$Filter = "Name='$EscapeGroupName'"
$oGroup = $null

$oGroup = Get-WmiInstanceNoAbort -sNamespace $NameSpace -sClassName $ClassName -sFilter $Filter -useCim $useCim

if ($oGroup.Count -gt 1 )
{
$oGroup = $oGroup[0]
}

return $oGroup
}

function Print-Header($maxLen,$gLen,$stLen)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$Header = "Name ";
$hLine = "----"
$State = "State "
$hState = "-----"
$grp = "OwnerGroup "
$hgrp = "----------"
$rt = "ResourceType"
$hrt = "------------"



if ($maxLen -gt $Header.Length)
{
$Header = $Header.PadRight($maxLen + 1)
$hLine = $hLine.PadRight($maxLen,"-")
}

if ($stLen -gt $hState.Length )
{
$State = $State.PadRight($stLen + 2)
$hState = $hState.PadRight($stLen,"-")
}

if ($gLen -gt $grp.Length )
{
$grp = $grp.PadRight($gLen +1)
$hgrp = $hgrp.PadRight($gLen,"-")
}

$Header = $Header + $State + $grp + $rt
$hLine = "$hLine $hState $hgrp $hrt"

Write-Host $Header
Write-Host $hLine
}

function Get-Resources(
$oGroup
)
{
$ErrorActionPreference = 'SilentlyContinue'
$error.Clear()

$result = $null
$ClassName = "MSCluster_ResourceGroupToResource"
$wmiAssoc = "MSCluster_Resource"
$NameSpace = "root\mscluster"

if ($null -eq $oGroup)
{
return $null
}


$useCim = Check-CimInstance -oWmiInstance $oGroup

if($null -eq $useCim)
{
return $result
}

$oResources = $null
$oResources = Get-WmiAssociatorInstanceNoAbort -sNamespace $NameSpace -sAssociatorName $ClassName -oWmiInstance $oGroup -relatedClass $wmiAssoc

if(0 -ne $error.Count)
{
$e = $error[0].Exception.Message
Write-Host "Cannot get resources in group. Error: $e"
return $result
}


$stLen = 5
$maxLen = 4
$gName = $oGroup.Name
$gLen = $gName.Length

if ($gLen -lt 10)
{
gLen = 10
$gName = $gName.PadRight($gLen +1)
}

if ($null -eq $oResources -or 0 -eq $oResources.Count)
{
Write-Host " "
Print-Header -maxLen $maxLen -gLen $gLen -stLen $stLen
return
}

foreach($oResource in $oResources)
{

if ($oResource.Name.Length -gt $maxLen)
{
$maxLen = $oResource.Name.Length;

}

if (0 -ne $oResource.Name.Length)
{
$State = ConvertNumericResourceStateToString -state $oResource.State
if ($State.Length -gt $stLen)
{
$stLen = $State.Length
}
}

}

Write-Host " "
Print-Header -maxLen $maxLen -gLen $gLen -stLen $stLen

$maxLen++
$stLen++

foreach($oResource in $oResources)
{

if ([string]::IsNullOrEmpty($oResource.Name))
{
continue
}

$Name = $oResource.Name
$Name = $Name.PadRight($maxLen)
$State = ConvertNumericResourceStateToString -state $oResource.State
$State = $State.PadRight($stLen)
$rType = $oResource.Type
$Name = $Name + $State + $gName + " " + $rType

Write-Host $Name

}

Write-Host " "

return;
}


Function Get-ScriptParams([string]$fullscriptname, [ref]$GroupName)
{
$ErrorActionPreference = 'SilentlyContinue' # Scoped only to function
$error.Clear()

$params = Get-CmdParams -fullname $fullscriptname -MaxCount 1

if ($null -eq $params -or 0 -eq $params.Count)
{
return
}

if ($null -eq $params.Count -or 1 -eq $params.Count)
{
if ($null -ne $GroupName) { $GroupName.Value = $params }
return
}

if ($params.Count -gt 1 )
{
if ($null -ne $GroupName) { $GroupName.Value = $params[0] }
}

return
}
#==========================================================================
# Main
#==========================================================================

$GroupName = ""
$fullscriptname = $MyInvocation.MyCommand.Definition

Get-ScriptParams -fullscriptname $fullscriptname -GroupName ([ref] $GroupName)
Main
</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>ClusterGroupDiag.js</Name>
<Contents><Script>function alert($message)
{
WScript.Echo($message);
}

function exit($message)
{
alert($message);
WScript.Quit(0);
}

String.prototype.trim = function()
{
return this.replace(/^\s+|\s+$/gm,'');
}

String.prototype.replaceAll = function (str1, str2, ignore) {
return this.replace(new RegExp(str1.replace(/([\/\,\!\\\^\$\{\}\[\]\(\)\.\*\+\?\|\&lt;\&gt;\-\&amp;])/g, "\\$&amp;"), (ignore ? "gi" : "g")), (typeof (str2) == "string") ? str2.replace(/\$/g, "$$$$") : str2);
}


String.prototype.padRight = function ($c,$n) {
if ("number" !== typeof ($n) || "string" !== typeof ($c) || 0 === $c.length) { return this; }
if (this.length &gt;= $n) { return this; }
return this + Array($n - this.length + 1).join($c);
}

Enumerator.prototype.forEach = function($f,$params)
{
var $result = null;

if ("function" !== typeof($f)) { return undefined;}

for(;!this.atEnd();this.moveNext())
{
$result = $f(this.item(),$params);
if (undefined === $result)
{
break;
}
}

return $result;
}

function getPropCount($O)
{
var $i = 0;
for ($i in $O) { $i++; }

return $i;
}

function GetErrorDetails($e)
{
if (!($e instanceof Error)) { return; }

if ($e.number &lt;0)
{
$e.number = 0xffffffff + $e.number + 1;
}

return " Error details: Error code: 0x" + $e.number.toString(16) + ". Description : " + $e.description;
}

function getEscapedName($Name)
{
return $Name.replaceAll("\\", "\\\\").replaceAll("'", "\\'");
}

function getAescapedName($Name) {
return $Name.replaceAll("\\", "\\\\\\\\").replaceAll("\"", "\\\\\\\"");
}

function getClusterService($NodeName)
{
$wmiPath = "winmgmts:{impersonationLevel=impersonate,authenticationLevel=pktPrivacy}!\\\\" + $NodeName + "\\root\\mscluster";
var Service = null;
var $message = "";

try
{
Service = GetObject($wmiPath);
}
catch(e)
{
$message = GetErrorDetails(e);
$message = "Cannot connect to Cluster Namespace. " + $message;
exit($message);
}

return Service;
}

function GetWmiQuery($query, $Service, $message, $IsA) {
var $coll = null;
var $iterator = null;
var $Count = null;
var $Message = null;

try {
$coll = $Service.ExecQuery($query);
$Count = $coll.Count;
if (0 !== $Count) {
$iterator = new Enumerator($coll);
}
}
catch (e) {
$iterator = undefined;
if (!$IsA) {
$Message = GetErrorDetails(e);
$Message = $message + "\n" + $Message;
alert($Message);
}
}
finally {
delete $coll;
$coll = null;
}

return $iterator;

}

function GetWmiAssoc($Object, $AssocName, $message, $IsA) {
var $collection = null;
var $iterator = null;
var $Count = null;
var $Message = null;

try {
$coll = $Object.Associators_($AssocName, "", "", "", false, false, "", "", 0);
$Count = $coll.Count;
if (0 !== $Count) {
$iterator = new Enumerator($coll);
}

} catch (e) {
$iterator = undefined;
if (!$IsA) {
$Message = GetErrorDetails(e);
$Message = $message + "\n" + $Message;
alert($Message);
}
}
finally {
delete $coll
$coll = null;
}

return $iterator;

}

function checkWmiMethod($Object, $MethodName) {
if (null === $Object || undefined === $Object || null === $MethodName || undefined === $MethodName || "object" !== typeof ($Object)) {
return false;
}

var $methods = null;
var $result = true;
$methods = $Object.Methods_;

if (null === $methods || undefined === $methods || "object" !== typeof ($methods)) { delete $methods; $methods = null; return false; }
if (0 === $methods.Count || null === $methods.Count) { delete $methods; $methods = null; return false; }

try {
$methods.Item($MethodName);
} catch (e) {
$result = false;
}

delete $methods;
$methods = null;

return $result;
}

function getClusterGroup($GroupName,$Service)
{
if (undefined === $GroupName || null === $GroupName)
{
return undefined;
}

var $query = "select Name,State from MSCluster_ResourceGroup where Name='" + getEscapedName($GroupName) + "'";
var $iterator = GetWmiQuery($query,$Service,"Cannot get resource group name " + $GroupName + " . ");

return (null !== $iterator &amp;&amp; undefined !== $iterator) ? $iterator.item() : $iterator;
}

function addResource($rpath,$Resources)
{
if (undefined === $Resources || null === $Resources || "object" !== typeof ($Resources)) { return undefined; }
if (undefined === $rpath || null === $rpath || "object" !== typeof ($rpath) ) { return undefined; }
if (undefined === $rpath.Dependent || null === $rpath.Dependent || "string" !== typeof ($rpath.Dependent)) { return 0; }

var $r = null;

try {
$r = $Resources.service.Get($rpath.Dependent)
$Resources.rr.push($r);

} catch (e) {

}
finally
{
delete $r;
$r = null
}

return 0;
}

function getDependentResouces($ResourceName,$Service)
{
if (undefined === $ResourceName || null === $ResourceName) {
return undefined;
}

if (undefined === $ResourceName || null === $ResourceName || "object" !== typeof ($Service)) { return undefined; }

$ResourceName = getAescapedName($ResourceName);

var $query = "select Dependent from MSCluster_ResourceToDependentResource where Antecedent=\"MSCluster_Resource.Name=\\\"" + $ResourceName + "\\\"\"";
var $iterator = GetWmiQuery($query, $Service, "Cannot get dependent resources for " + $ResourceName + " . ");

if (null === $iterator || undefined === $iterator) { return $iterator;}
var $Resources = {rr:[],service:$Service};

if (undefined === $iterator.forEach(addResource, $Resources)) { return undefined; }
if (0 === $Resources.rr.length) { return null;}


return $Resources.rr;

}

function getClusterResource($ResourceName,$Service,$all)
{
if (undefined === $ResourceName || null === $ResourceName)
{
return undefined;
}

var $query =" from MSCluster_Resource where Name='" + getEscapedName($ResourceName) + "'"
$query = !$all ? "select Name,State" + $query : "select *" + $query;
var $iterator = GetWmiQuery($query,$Service,"Cannot get resource [" + $ResourceName + "] . ");

return (null !== $iterator &amp;&amp; undefined !== $iterator) ? $iterator.item() : $iterator;
}

function getResourceNode($r) {
if (undefined !== $r.OwnerNode &amp;&amp; null !== $r.OwnerNode) { return $r.OwnerNode; }

var $iterator = GetWmiAssoc($r, "MSCluster_NodeToActiveResource", "Cannot get active owner of resource.",true);
if (undefined === $iterator || null === $iterator) { return undefined;}
var $n = $iterator.item();
if (undefined === $n || null === $n) { return ""; }

return (null !== $n.Name &amp;&amp; undefined !== $n.Name) ? $n.Name : "";
}

function getResourceGroup($r) {

if (undefined !== $r.OwnerGroup &amp;&amp; null !== $r.OwnerGroup) {return $r.OwnerGroup;}

var $iterator = GetWmiAssoc($r, "MSCluster_ResourceGroupToResource", "Cannot get resource group.",true);
if (undefined === $iterator || null === $iterator) { return ""; }
var $g = $iterator.item();
if (undefined === $g || null === $g) { return ""; }

return (null !== $g.Name &amp;&amp; undefined !== $g.Name) ? $g.Name : "";
}

function ConvertNumericResourceStateToString($state)
{

$States = ["Inherited", "Initializing", "Online", "Offline", "Failed"];

if ($state &gt;= 0 &amp;&amp; $state &lt; 5) { return $States[$state]; }
if (128 === $state) { return "Pending"; }
if (129 === $state) { return "Online Pending"; }
if (130 === $state) { return "Offline Pending"; }

return "Unknown";
}

function ConvertNumericResourceGroupStateToString($state) {

$States = ["Online", "Offline", "Failed", "Partial Online","Pending"];

if ($state &gt;= 0 &amp;&amp; $state &lt; 5) { return $States[$state]; }

return "Unknown";
}

function getCmdFileName() {
var $f = WScript.ScriptName;
var $p = WScript.ScriptFullName;
var $nf = "";

if (undefined === $f || null === $f || "string" !== typeof ($f)) { return null; }
if (undefined === $p || null === $p || "string" !== typeof ($p)) { return null; }
if (0 === $f.length || 0 === $p.length || $p.length &lt;= $f.length) { return null; }

return $p.substring(0, $p.length - $f.length) + "vbparams.txt";
}

function parseCmd($s,$d)
{
if ("string" !== typeof ($s) || undefined === $s || null === $s ) { return null; }
if ("string" !== typeof ($d) || undefined === $d || null === $d || 0 === $d.length) { $d = "="; }

var $l = $s.length;
var $i = -1;

if (0 === $l) { return null; }

$i = $s.indexOf($d, 0)

if (-1 === $i) { return null; }

$i += $d.length;

return $l &lt;= $i ? "" : $s.slice($i,$l);
}


function getCmdParams($MaxParams) {
var $fso = null;
var $fl = null;
var $filename = getCmdFileName();
var $args = [];
var $i = 0;
var $v = null;
if (null === $filename) { return $args; }
if (undefined === $MaxParams || null === $MaxParams || "number" !== typeof ($MaxParams)) { $MaxParams = 0; }

try {
$fso = new ActiveXObject("Scripting.FileSystemObject");
if (!$fso.FileExists($filename)) { return $args; }
$fl = $fso.OpenTextFile($filename,1,false,-1);
if (null === $fl || undefined === $fl) { return null; }
$i = 0;
for (; !$fl.AtEndOfStream;) {
$v = parseCmd($fl.ReadLine(), "=");
if (null !== $v) {
$i++;
if ($i &gt; $MaxParams &amp;&amp; 0 !== $MaxParams) { break; }
$args.push($v);
}

}
} catch (e) {
$args = null;
alert("Cannot read command line parameters.");
}
finally {
if (null !== $fl &amp;&amp; 0 !== $i) { $fl.Close(); }
}

return $args;
}



function getResourcesInGroup($g) {

if (undefined === $g || null === $g || "object" !== typeof ($g)) { return null; }
var $iterator = GetWmiAssoc($g, "MSCluster_ResourceGroupToResource", "Cannot get resources in group.", true);

return $iterator;
}

function printHeader($maxLen, $gLen, $stLen)
{
var $Header = "Name ";
var $hLine = "----";
var $State = "State ";
var $hState = "-----";
var $grp = "OwnerGroup ";
var $hgrp = "----------";
var $rt = "ResourceType";
var $hrt = "------------";
var s = "";
var nl = "";

if ($maxLen &gt; $Header.length)
{
$Header = $Header.padRight(" ",$maxLen + 1);
$hLine = $hLine.padRight("-", $maxLen);
}

if ($stLen &gt; $hState.length )
{
$State = $State.padRight(" ", $stLen + 2);
$hState = $hState.padRight("-", $stLen);
}

if ($gLen &gt; $grp.length )
{
$grp = $grp.padRight(" ", $gLen + 1);
$hgrp = $hgrp.padRight("-", $gLen);
}

$s = $Header + $State + $grp + $rt
$nl = $hLine + " " + $hState + " " + $hgrp + " " + $hrt

alert($s);
alert($nl);
}


function getMaxDep($p, $o) {
if (undefined === $p || null === $p || "object" !== typeof ($p)) { return undefined; }
if (undefined === $p.Name || null === $p.Name || "string" !== typeof ($p.Name)) { return undefined; }

var $r = {};
$r.State = ConvertNumericResourceStateToString($p.State);
$r.Name = $p.Name;
$r.Type = (undefined === $p.Type || null === $p.Type || "string" !== typeof ($p.Type)) ? "" : $p.Type;
if ($r.Name.length &gt; $o.mR) { $o.mR = $p.Name.length; };
if ($r.State.length &gt; $o.mS) { $o.mS = $r.State.length; }

$o.rd.push($r);

return 0;
}

function printGroup($g) {
if (null === $g || undefined === $g || "object" !== typeof ($g)) { alert("Wrong cluster group provided."); return; }

var $gN = (null === $g.Name || undefined === $g.Name || "string" !== typeof ($g.Name)) ? "" : $g.Name;

var $it = getResourcesInGroup($g)
var $p = { mR: 4, mG: $gN.length &gt;10 ? $gN.length: 10, mS: 5,rd:[]};

if (undefined === $it) { return; }
if (null === $it) {
alert("\n");
printHeader($p.mR, $p.mG, $p.mS);
alert("\n");
return;
}

if ($gN.length &lt; 10) { $gN = $gN.padRight(" ", 10); }

var $i = 0;

try {
if (undefined === $it.forEach(getMaxDep, $p)) { return; }
alert("\n");
printHeader($p.mR, $p.mG, $p.mS);
for(;$i &lt; $p.rd.length;$i++)
{
alert($p.rd[$i].Name.padRight(" ", $p.mR) + " " + $p.rd[$i].State.padRight(" ", $p.mS) + " " + $gN + " " + $p.rd[$i].Type);
}
alert("\n");
} catch (e) {

}

return;
}

function getParams($params) {

if ("object" !== typeof ($params)) {
return false;
}

var $args = getCmdParams(1);

if (null === $args) { exit("Wrong number of arguments.");}

if ($args.length &lt; 1) {
exit("Wrong number of arguments.");
}

$params.GroupName = $args[0];

if (0 === $params.GroupName.length || 0 === $params.GroupName.trim().length) {
exit("Cluster group name is empty.");
}

return true;
}

function Main()
{
var $params = {};

getParams($params);

var $Service = null;
var $oGroup = null;

$Service = getClusterService(".");
$oGroup = getClusterGroup($params.GroupName, $Service);

if (null === $oGroup) {
delete $Service;
$Service = null;
exit("Cluster resource group " + $params.GroupName + " is not found.");
}
else if (undefined === $oGroup) {
delete $Service;
$Service = null;
exit("Cluster resource group [" + $params.GroupName + "] is not found.");
}
else if ("object" !== typeof ($oGroup)) {
delete $Service;
$Service = null;
exit("Wrong wmi object provided");
}

printGroup($oGroup);

delete $oGroup;
delete $Service;
$ooGroup = null;
$Service = null;

}

Main();
</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>vbparams.txt</Name>
<Contents><Script>

=$Target/Property[Type="ClusLibrary!Microsoft.Windows.Cluster.HostedGroup"]/EscapedGroupName$

</Script></Contents>
<Unicode>true</Unicode>
</File>
<File>
<Name>psparams.txt</Name>
<Contents><Script>

=$Target/Property[Type="ClusLibrary!Microsoft.Windows.Cluster.HostedGroup"]/EscapedGroupName$

</Script></Contents>
<Unicode>true</Unicode>
</File>
</Files>
</ProbeAction>
</Diagnostic>