OpsMgr 2012 PowerShell: updated collection of one-liners

Stefan Stranger pointed to great post PowerShell Magazine website by Shay Levy that demonstrates how to make comparisions between two versions of PowerShell. When I began digging around a few months ago, I quickly learned that while some changes are superficial, others run deeper than changes in the verb-noun cmdlet naming conventions. As the release candidate (RC) approaches, I wanted to begin providing updated resources, including translations of OpsMgr 2007 resources updated for OpsMgr 2012. If you’ve not begun to explore the differences, Oskar Landman recently posted a great roadmap.

Below are the one-liners Scott Moss pulled together for OpsMgr 2007, updated here for OpsMgr 2012.

NOTE: These are each single line PowerShell scripts. If its more than one line, reformat for a single line!

Retrieving cmdlets associated with a module

Retrieve PowerShell Cmdlets

Get-Command -Module OperationsManager | Select-Object -Property Name

Retrieve PowerShell Cmdlets and Parameters

Get-Command -Module OperationsManager | Select-Object -Property Name,@{Name=’Parameters’;Expression={(Get-Command $_).Parameters.Keys}}

OpsMgr 2012 Command Shell One-liners

In this case, you’ll see the primary changes are in the cmdlet naming conventions. Resolve-alert is now ‘Set-ScomAlert –ResolutionState 255’. Get-Alert is a simple change to Get-ScomAlert

#Resolve informational alerts that are created by a rule

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $False)}| set-scomalert -ResolutionState 255 | out-null

#Resolve information alerts that are created by a monitor

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $True)}| set-scomalert -ResolutionState 255 | Out-Null

#Get a count of Warning alerts created by a rule 

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $false)}).count

#Get a count of Warning alerts created by a monitor VERIFIED

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $true)}).count

#Report listing of Warning Alerts created by a rule

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $False)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table -auto

#Report listing of Warning Alerts created by a monitor 

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $True)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table -auto

#resolve-scomalerts that are created by a rule on Warning alerts 

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $False)} | set-scomalert -ResolutionState 255 | out-null

#resolve-scomalerts that are created by a monitor on Warning alerts 

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”1”’ | where-object {($_.IsMonitorAlert -eq $True)} | set-scomalert -ResolutionState 255 | out-null

#Get a count of Critical alerts created by a rule

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | where-object {($_.IsMonitorAlert -eq $False)}).count 

#Get a count of Critical alerts created by a monitor

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | Where-Object {($_.IsMonitorAlert -eq $True)}).count

#Report listing of Critical Alerts created by a rule

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | where-object {($_.IsMonitorAlert -eq $False)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table –auto

#Report listing of Critical Alerts created by a Monitor

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | Where-Object {($_.IsMonitorAlert -eq $True)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table -auto

#resolve-scomalerts that are created by a rule on Critical alerts

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | where-object {($_.IsMonitorAlert -eq $False)} | set-scomalert -ResolutionState 255 | out-null

#resolve-scomalerts that are created by a monitor on Critical alerts

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”2”’ | where-object {($_.IsMonitorAlert -eq $True)} | set-scomalert -ResolutionState 255 | out-null

#Resolve all Alerts that are created by a rule

get-scomalert -criteria ‘ResolutionState = ”0”’ | where-object {($_.IsMonitorAlert -eq $False)}| set-scomalert -ResolutionState 255 | out-null

#Resolve all Alerts that are created by a monitor

get-scomalert -criteria ‘ResolutionState = ”0”’ | where-object {($_.IsMonitorAlert -eq $True)}| set-scomalert -ResolutionState 255 | out-null

#Get a count of informational alerts created by a rule

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $false)}).count

#Get a count of informational alerts created by a monitor

(get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $true)}).count

#Report listing of Informational Alerts created by a rule

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $False)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table –auto

#Report listing of Informational Alerts created by a monitor

get-scomalert -criteria ‘ResolutionState = ”0” AND Severity = ”0”’ | where-object {($_.IsMonitorAlert -eq $True)} |Group-Object Name |Sort -desc Count | select-Object Count, Name |Format-Table -auto

Additional OpsMgr 2012 Resources

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.