SCOM Get-Alert -critera or where-object?

For any of you that work with SCOM and the Operations Manager Shell on a regular basis, you’d recognize this sort of command.

get-alert | ? {$_.Name -eq “Unable to Verify Run As Account”}

If you work with SCOM, then you’d probably know that this command will work fine and it will retrieve the intended results (which is to return all alerts that have the name “Unable to Verify Run As Account”). Of course when you’re sitting there waiting for the results to come back, any delay feels like a long delay and this command will probably take a long time – certainly a lot longer that it needs to. So I decided to find out exactly how long it was taking by using “Measure-Command”.

PS Monitoring:theScomLab01
>measure-command {get-alert | ? {$_.Name -eq “Unable to Verify Run As Account”}}

Days              : 0
Hours             : 0
Minutes           : 1
Seconds           : 11
Milliseconds      : 85
Ticks             : 710856440
TotalDays         : 0.000822750509259259
TotalHours        : 0.0197460122222222
TotalMinutes      : 1.18476073333333
TotalSeconds      : 71.085644
TotalMilliseconds : 71085.644


 

Now let’s compare that with this command:

PS Monitoring:theScomLab01
>measure-command {get-alert -criteria ‘Name = ”Unable to Verify Run As Account”’}

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 2
Milliseconds      : 440
Ticks             : 24404262
TotalDays         : 2.82456736111111E-05
TotalHours        : 0.000677896166666667
TotalMinutes      : 0.04067377
TotalSeconds      : 2.4404262
TotalMilliseconds : 2440.4262


As you can see from the above results. Using Get-Alert with the -Criteria parameter is clearly the winner. It took 2 seconds to return results, compared with 1 minute 11 seconds. Clearly the -Criteria version is much quicker because we’re selectively retrieving only the relevant alerts. In the other version we’re first getting all alerts and then picking out the ones we want. So the moral of the story here is: Check to see if there’s a better way.

 

If you’re interested, these SCOM cmdlets support the “-Criteria” parameter:

Get-Alert
Get-Diagnostic
Get-Discovery
Get-Event
Get-Monitor
Get-MonitoringObject
Get-Rule
Get-Task

 

 
Comments

No comments yet.

Leave a Reply