Summarizing your Agent States with PowerShell

I like to know what the overall state of my SCOM agents are. Truthfully 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

 

 
Comments

No comments yet.

Leave a Reply