Hi,
I am trying to create a Dashboard view to list the Grayed Out servers in my SCOM 2012 environment by using the script below but it does not work as expected.
Is there something wrong with this script or could you suggest me any other solution please?
#Get all agent objects which are not available (grey)
$agentclass = Get-SCOMClass -Name "Microsoft.SystemCenter.Agent"
$agentobjects = Get-SCOMMonitoringObject -Class:$agentclass | Where-Object {$_.IsAvailable -eq $false}
foreach ($agent in $agentobjects)
{
$dataObject = $ScriptContext.CreateFromObject($agent, "Id=Id,State=HealthState,Display Name=DisplayName", $null)
#Get the watcher state for the agent
$watcher = Get-SCOMClass -name "Microsoft.SystemCenter.HealthServiceWatcher"| get-scomclassinstance | Where-Object {$_.Displayname -eq $agent.DisplayName}
$dataObject["Watcher State"] = $watcher.HealthState.toString()
$ScriptContext.ReturnCollection.Add($dataObject)
}
Thanks
Srini