SCOM 2012 – Export Grey Agents using Powershell

There was a request in the TechNet forum to get all grey agents in SCOM 2012 using Powershell and export the Displayname and HealthState into a file. Because I haven’t seen a solution I thought I will share these few lines of code maybe you can use them also.

#Import the OperationsManager module
Import-Module OperationsManager
#Define the output file
#Get the agent class and the each object which is in a grey state
$agent = Get-SCClass -name “Microsoft.SystemCenter.Agent
$objects = Get-SCOMMonitoringObject -class:$agent | where {$_.IsAvailable –eq $false}
#Export each objet into a file
ForEach ($object in $objects){
$object.DisplayName+ “,”+ $object.HealthState | Out-File $file -Append

There is a similar solution for SCOM 2007 R2 see here.

Update 02.09.2012:

Graham Davies made me aware that this agent’s health state is the last state the agent had before it went “grey”.  Well if this is not the way you want it then you might consider changing to use the health service watcher class.

In order to get both states I wrote a Powershell script which will dump the agent display name, agent health state AND the watcher health state into a Excel sheet.

The agent state in a grey condition might look like this…


…and the watcher health state looks like this…


…the Excel output will show you this information…


If you call the script you need to provide a mangement server name as input parameter like this…


and after some time the Excel file will be saved as “GreyAgents.xslx” on your Desktop.



Download it here on skydrive

Note: I tested the script using Excel 2010 and SCOM 2012. In order to function properly make sure you set your “Regional Settings” where you have the Excel installed to English (United States).


If you encounter any problems let me know!




  1. Hi Stefen,

    I am getting the bellow error.:

    Unable to find type [parameter(mandatory=$true)]: make sure that the assembly containing this type is loaded.
    At C:\Documents and Settings\My_Profile\Desktop\GreyedOut.ps1:1 char:35
    + Param([parameter(mandatory=$true)][ <<<< String]$scom)

    Can you help me out.

  2. Hi Stefan,

    Thanks for the script, It is working fine in my environment.
    But it took 7 hours to complete as we are monitoring 5000 agents in our SCOM estate.

    Is it possible to run the script to get the grayed agent on the on each management server separatly, so that the agent count will be less. Can you please help me edit the script to get grayed agent on the particular management server?

    Thanks and Regards

Leave a Reply

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

You are commenting using your 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