Agent Health State Report with Powershell

Everyone likes to know what the overall state of their SCOM agents are. You can see this info in the console, but where’s the fun in that? Here’s a PowerShell way to do it…

This script will produce a list of the total number of agents that are in these Health States: Healthy (Success) , Warning , Critical (Error) or Uninitialized.

$healthy = $uninitialized = $warning = $critical =0

switch (Get-Agent | Select-Object HealthState) {
 {$_.HealthState -like “Success”} {$healthy++}
 {$_.HealthState -like “Warning”}  {$warning++}
 {$_.HealthState -like “Error”} {$critical++}
 {$_.HealthState -like “Uninitialized”} {$uninitialized++}
}

“Agents Healthy ……………… = $healthy”
“Agents Warning ……………… = $warning”
“Agents Critical……………… = $critical”
“Agents Uninitialized…………. = $uninitialized”

The output will look something like this…

Agents Healthy ……………… = 200
Agents Warning ……………… = 5
Agents Critical……………… = 2
Agents Uninitialized…………. = 35

Advertisements
This entry was posted in Powershell for SCOM, SCOM Agents and tagged , , . Bookmark the permalink.

2 Responses to Agent Health State Report with Powershell

  1. Graham says:

    Be careful with this as you are targetting the agent health state. If a server with an agent installed is in a healthy state when it is shut down, then this code will list that agent as healthy, even though it is unavailable.

    If you look in the SCOM console, monitoring, operations manager, agent health state, details – you’ll see what I mean. The agent is greyed out but the actual health state listed (and which this script pulls back) is healthy.

  2. scompanion says:

    Thanks for the feedback Graham, much appreciated.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s