Blog
By Pete Zerger on 1/14/2010 10:43:16 PM • Rank (3505) • Views 3775
0

0

 

image

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.

$WCC = get-monitoringclass -name "Microsoft.SystemCenter.Agent"

$MO = Get-MonitoringObject -monitoringclass:$WCC | where {$_.IsAvailable -eq $false}

$MO | select DisplayName

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

SELECT ManagedEntityGenericView.DisplayName, ManagedEntityGenericView.AvailabilityLastModified

FROM ManagedEntityGenericView

INNER JOIN ManagedTypeView ON ManagedEntityGenericView.MonitoringClassId = ManagedTypeView.Id

WHERE (ManagedTypeView.Name = 'microsoft.systemCenter.agent') AND (ManagedEntityGenericView.IsAvailable = 0)

ORDER BY ManagedEntityGenericView.DisplayName

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!

Comments (3) - Comment RSS
Babu wrote: on May 01, 2010 06:07 AM
Excellent.....as you rightly said first power-shell script for grayed out agents.....
Babu wrote: on May 01, 2010 06:59 AM
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?
Dayved wrote: on Aug 18, 2011 02:45 PM
This is faster:

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


Who Viewed
Who Reviewed
Categories
Related Pages
Shortened URL
http://tinyurl.com/yc5pajc

Top Contributors
Featured Members
Pete Zerger
Points: 65622
Level: System Center Expert
Tommy Gunn
Points: 42748
Level: System Center Expert
Simon Skinner
Points: 40804
Level: System Center Expert
Stefan Koell
Points: 28999
Level: System Center Expert
Andreas Zuckerhut
Points: 27734
Level: System Center Expert