Script

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
$file=”C:\Temp\GreyAgents.txt”
#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…

image

…and the watcher health state looks like this…

image

…the Excel output will show you this information…

image

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

image

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

Script:

image

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).

image 

If you encounter any problems let me know!

Cheers,

Stefan

9 Replies to “SCOM 2012 – Export Grey Agents using Powershell

  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 SettingsMy_ProfileDesktopGreyedOut.ps1:1 char:35
    + Param([parameter(mandatory=$true)][ <<<< String]$scom)

    Can you help me out.

    1. Hi Vishal

      Did you install the Operations Manager 2012 console on the system you are executing the script? The script needs Excel 2010 and the SCOM 2012 console to be installed.

      Regards,

      Stefan

    1. Hi Vishal

      Yes it would be possible, but you would need to modify certain SCOM commands in the script which are specific to SCOM 2007 R2.

      Regards,

      Stefan

  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
    Karthick

  3. Hi Stefan,
    We are using SCOM 2012R2, and the script is not giving me any output.

    Can you please help me on this.

    Thanks,
    Deepak

Leave a Reply to Stefan Roth Cancel reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.