Wednesday, May 6, 2015

PowerShell One Liner: Show All Open Alerts Sorted On Highest Count By Name

Issue
The SCOM 2012x Console isn’t really fast. And sometimes (or even more than that…) it misses certain functionality. Suppose you’ve got a whole bunch of open Alerts and you want to know what Alerts (based on their Names) are ‘fired’ the most.

Even better, you would like to have an overview of it, where all Alerts are sorted based on their name with the highest count on top.

Sadly this kind of basic functionality isn’t present in SCOM 2012x. Gladly this can be done easily in PowerShell with a single one liner (when you forget the line to load the OperationsManager Module that is).

Solution
Run this on a box which has the SCOM 2012x Console installed with the SCOM 2012x PS Module:

Import-Module OperationsManager
New-SCManagementGroupConnection -ComputerName [NAME OF SCOM 2012x MANAGEMENT SERVER]
Get-SCOMAlert -Criteria "ResolutionState <> '255'" | Sort Name | Group Name | Sort Count -Descending | Out-GridView

And this is what you get:
image


Recap
I know. This is very basic stuff but you would be surprised how many people don’t know this nice one liner.


Additional Comment
Out-GridView only works when PowerShell ISE is installed. Many times the PS ISE isn’t present on servers but on workstations instead.

5 comments:

John Bradshaw said...

Nice one!! Thx Marnix.

nicolas milbrand said...

Hi Marnix,
You can do it with SCOM Console with Alert views and "Group items by Name"

Marnix Wolf said...

Hi Nicolas.

Thanks for the comment. However, in bigger environments with many Alerts all Alerts aren't collapsed so I have to cycle through it all in order to get a clear overview of the count.

The PS oneliner delivers just that. But you're right, the SCOM Console can deliver it.

Cheers,
Marnix

Manohar Mekala said...

Thanks for sharing. Tried the same from a Client and got this error.
Get-SCOMAlert : The Data Access service is either not running or not yet initialized. Check the event log for more information.
At line:1 char:1
+ Get-SCOMAlert -Criteria "ResolutionState <> '255'" | Sort Name | Group Name | So ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (Microsoft.Syste...tSCAlertCommand:GetSCAlertCommand) [Get-SCOMAlert], ServiceNotRunningException
+ FullyQualifiedErrorId : ExecutionError,Microsoft.SystemCenter.OperationsManagerV10.Commands.GetSCAlertCommand

Looked around in ISE and found this command 'Get-SCOMCommand'. When you run it, you get the list of SCOM commands to use from a Client (in my case Win7). Looked through the commands and found something interesting 'Start-OperationsManagerClientShell'.
Added that to the script and this worked for me.
Import-Module OperationsManager
Start-OperationsManagerClientShell
Get-SCOMAlert -Criteria "ResolutionState <> '255'" | Sort Name | Group Name | Sort Count -Descending | Out-GridView

Marnix Wolf said...

Hi Manohar.

This happens when you run this PS script/oneliner from a system which isn't a Management Server.

I've updated the script with this line:

New-SCManagementGroupConnection -ComputerName [NAME OF SCOM 2012x MANAGEMENT SERVER]

Now it will work from any non-Management Server. Of course you need to have the SCOM 2012x Console to be installed locally otherwise these PS cmdlets won't work.

Thanks for your feedback.

Cheers,
Marnix