Powershell Tip: Operations Manager 2007 Top Alerts Report - Part 1
My favorite characteristic of Command Shell is the availability of the huge array of rich formatting, filtering and sorting options. Oh, and the fact that I can do almost anything in one line. Put these two things together, and we can do some pretty amazing stuff. Watch as we take a MOM 2005 function with it’s own Solution Accelerator (the Alert Tuning SA), complete MOM Reports - and deliver a functional substitute in a single line of Powershell code.
Let’s have a look at the solution and deconstruct what we’re doing. In addition to the obvious get-alert cmdlet, we’re using 4 additional cmdlets together here, each of which has a purpose in filtering, sorting and formatting the output.
I give you, the Operations Manager 2007 Top Alerts Report. Run the following line of code in the Command Shell window:
get-alert | Group-Object Name |Sort -desc Count | select-Object -first 5 Count, Name |Format-Table -auto
And you get output that looks like this:
Here is the role of each cmdlet in the one-liner. If you don’t believe me, remove the cmdlet at the far right, re-run the one-liner and see the difference in output with each subsequent run.
-
Get-alert - Returns all alerts
-
Group-object - Returns the list with a count of the number of times the alert by a particular name occurs
-
Sort - To sort the list of alerts in descending order by count.
-
Select-Object - Allows us to remove the group column that obscures the display of the full alert name AND allows us to use the -first parameter to return only the top X alerts (top 5 in our example).
-
Format-table - with the -auto flag to left justify and remove the unnecessary space.
One line of code got us halfway there, but we’re really not done yet. In the next installment, we’ll dig into this output with some more Powershell to further filter our results based on date and time the alerts were raised and drill down to the problem computer(s).


March 18th, 2008 at 7:06 am
[…] LetÂ’s have a look at the solution and deconstruct what weÂ’re doing. In addition to the obvious get-alert cmdlet, weÂ’re using 4 additional cmdlets together here, each of which has a purpose in filtering, sorting and formatting the output.(continue at source) […]
March 20th, 2008 at 7:58 am
[…] I mentioned in a post earlier this week, I really like the many formatting options in Powershell. Here’s another formatting tip not […]
March 20th, 2008 at 1:59 pm
Sweet one liner Pete!
To get a report of Top New Alerts just add the Get-Alert criteria for Resolutionstate = 0 like below:
get-alert -criteria ‘ResolutionState = ”0”’ | Group-Object Name |Sort -desc Count | select-Object -first 5 Count, Name |Format-Table -auto
http://myitforum.com/cs2/blogs/smoss/default.aspx
Something I learned late last night: do not copy script code from an RSS reader like RSS Bandit, just get it directly from the web site.
March 21st, 2008 at 2:55 pm
[…] I mentioned in a post earlier this week, I really like the many formatting options in Powershell. HereÂ’s another formatting tip not […]
May 20th, 2008 at 5:22 am
[…] talked a few weeks ago about creating a Top Alerts Report in Powershell to improve upon the Top Alerts Report. So here are variations on that provides an additional […]
July 2nd, 2008 at 8:06 pm
[…] Zerger has a good example of a mini-report http://www.systemcenterforum.org/powershell-tip-operations-manager-2007-top-alerts-report-part-1/ . From his report I got the idea for these other […]