OpsMgr: Finding Grey Agents with Powershell



Here’s a winner from OpsMgr guru and bloggerAndreas “Tenchuu” Zuckerhut.

Q: Can I retrieve a list of uncommunicative (grey) agents with Powershell?

If you search the Internet for this topic, you’ll find T-SQL queries everywhere you look, but no Powershell alternative. T-SQL is an options, but generally never as a first choice. Powershell is faster and safer given there’s no chance you will inadvertently take something offline or delete in SQL Mgmt Studio.

A: The answer appears very simple – 3 lines of Powershell.

The SQL (listed here) works, but with a Powershell solution in hand, should be avoided.

NOTE: Several of us have tested this side-by-side with the T-SQL and seen identical results. We’d be interested to hear your experience when comparing the results of the Powershell versus the T-SQL query.

Well Done Andreas!

5 thoughts on “OpsMgr: Finding Grey Agents with Powershell

  1. Profile photo of BabuBabu

    I was trying to find the Lastheartbeat time for the grayed out agents using your script

    Any of the property (StateLastModified, LastModified, AvailabilityLastModified) doesn’t represents the last heartbeat time.

    Could you please help me to find the Lastheartbeat time using your script?

  2. Profile photo of DayvedDayved

    This is faster:

    $WCC = get-monitoringclass -name "Microsoft.SystemCenter.Agent";
    $MO = $WCC | get-monitoringObject -Criteria "IsAvailable = ‘False’";
    $MO | select DisplayName;

  3. Profile photo of DwayneDwayne

    Actually you will want to filter out agents in maintenance mode as you typically don’t want to count them as “grey”. ie If you’re doing this as a health check.

    (this example is for scom 2012 just add the filter for your 2007 solutions)

    $agent = Get-SCClass -name “Microsoft.SystemCenter.Agent”
    $objects = Get-SCOMMonitoringObject -class:$agent | where {$_.IsAvailable –eq $false -and $_.InmaintenanceMode -eq $false}

    then either a foreach loop or just display the results depending on what you are trying to do.

  4. Profile photo of DwayneDwayne

    Actually if you want to know what’s grey, without a Heartbeat failure alert, and a ticket number if the alerts been processed something like this might help

    Get-scomclassinstance never works for me if I specify a class and name it keeps telling me the data access layer is down when I do, so I’ve had to work around that

    $agent = Get-SCOMClass -name “Microsoft.SystemCenter.Agent”
    $objects = $agent | Get-SCOMClassInstance | where {$_.IsAvailable –eq $false -and $_.InmaintenanceMode -eq $false}

    $WatcherClass = Get-SCOMClass -name “Microsoft.SystemCenter.HealthServiceWatcher”
    $watcherObjectInstances = Get-SCOMClassInstance -class $WatcherClass

    ForEach ($object in $objects)
    $computername= $object.displayname

    $watcherobject = $watcherObjectInstances | where {$_.Displayname -eq $computername}

    $HBalert = $watcherobject|get-scomalert| Where {$_.Name -eq ‘Health Service Heartbeat Failure’ -and $_.ResolutionState -ne 255}

    IF ( $HBalert )
    write-host ‘There is an active heartbeat failure alert in the system’
    write-host ‘There is no active heartbeat failure alert in the system’

    IF ( $HBalert )
    write-host ‘Ticket ID ‘ $HBalert.ticketID

    There is an active heartbeat failure alert in the system
    Ticket ID 506007

Leave a Reply