Need a Script to find out the Grayed out agents in SCOM 2012

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












   





February 13th, 2015 3:55am

Hi,

Get-SCOMClass -Name "Microsoft.SystemCenter.Agent" | Get-SCOMClassInstance | ? {$_.isAvailable -eq $false}

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 9:58am

Try some of these:

Stefan

Maurice

Similar Topic

February 13th, 2015 10:56am

Thanks for your reply Alexis.

I managed to create it myself :)

I actually wanted include both the server state HealthState (Not Monitored) and Availability (Grayed out) list  and export it to a file.

However, I would like to create a Dashboard view with Powershell widget and view these servers there but I could not make it work.

Do you have any suggestions how to make this work?

Thanks.

Free Windows Admin Tool Kit Click here and download it now
February 13th, 2015 11:15am

$WCC = get-monitoringclass -name "Microsoft.SystemCenter.Agent"
$MO = Get-MonitoringObject -monitoringclass:$WCC | where {$_.IsAvailable -eq $false}
$MO | select DisplayName

See if the above works

February 14th, 2015 12:57pm

Hi, something like this?

$Agents = Get-SCOMClass -Name "Microsoft.SystemCenter.Agent" | Get-SCOMClassInstance | ? {$_.isAvailable -eq $false}

foreach ($Agent in $Agents)
{
$dataObject=$ScriptContext.CreateFromObject($Agent,"Id=Id,Health State=HealthState,DisplayName=DisplayName",$null)

$Watcher=Get-SCOMClass -Name "Microsoft.SystemCenter.AgentWatcher" | Get-SCOMClassInstance | ? {$_.'[System.Entity].DisplayName'.Value -eq $Agent.'[System.Entity].DisplayName'.Value} 

$dataObject["Watcher State"]=$ScriptContext.CreateWellKnownType("xsd://Microsoft.SystemCenter.Visualization.Library!Microsoft.SystemCenter.Visualization.OperationalDataTypes/MonitoringObjectHealthStateType",$watcher.healthstate.value__)

$dataObject["Watcher State isAvailable"]=$watcher.isAvailable

$ScriptContext.ReturnCollection.Add($dataObject)
}

Free Windows Admin Tool Kit Click here and download it now
February 16th, 2015 4:46am

It doesn't work Gautam.

I can run the script through PS console but could not get the output when I use the same script in SCOM Dashboard view.

Srini

February 17th, 2015 7:26am

Yes, i tried this script but it doesn't work either.

When i create a Dashboard view using this script the console closes every time.

Free Windows Admin Tool Kit Click here and download it now
February 17th, 2015 7:35am

Yes, i tried this script but it doesn't work either.

When i create a Dashboard view using this script the console closes every time.

it seems that the problem is in your environment, can you run any other simple script here?

February 17th, 2015 7:57am

Hi Blake,

Unfortunately none of the above references could actually help to achieve my requirement :(

Free Windows Admin Tool Kit Click here and download it now
February 20th, 2015 9:08am

Hi

Not sure if this is still useful but for anyone else coming across this thread, this should help:

http://blogs.msdn.com/b/wei_out_there_with_system_center/archive/2015/04/15/opsmgr-using-psgw-to-display-unhealthy-agents-of-instances-of-a-specific-class.aspx

Wei has also been a great help in assisting with dashboards when you want to get a property defined on a parent class included in the dashboard. E.g. if you want to base a dashboard on the agent class, be aware that many properties are inherited from the parent health service class. You can see these if you do a:

Get-SCOMClass -Name "Microsoft.SystemCenter.Agent" | get-scommonitoringobject | Select *

They are the properties that come up in []

E.g. to build a dashboard for version and patch list you can use the following (I appreciate you can use the Operations Manager agent view as well - this is really just as an example).

Get-SCOMClass -Name "Microsoft.SystemCenter.Agent" | get-scommonitoringobject | %{

$dataObject = $ScriptContext.CreateInstance("xsd://demolab.co.uk/MySchema");

$dataObject["Id"]=$_.Id.ToString();

$dataObject["Server Name"]=$_.DisplayName;

$dataObject["Version"]=$_."[Microsoft.SystemCenter.HealthService].Version".value;

$dataObject["Patch List"]=$_."[Microsoft.SystemCenter.HealthService].PatchList".value;

$ScriptContext.ReturnCollection.Add($dataObject)
}

Regards

Graham

Disclaimer:     
All information on this blog is provided on an as-is basis with no warranties and for informational purposes only. Use at your own risk. The opinions and views expressed in this blog are those of the author and do not necessarily state or reflect those of my employer.

June 17th, 2015 12:42pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics