OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell

As with several other areas of the Operations Manager Command Shell, disabling (or enabling) rules and monitors in bulk is quite easy, and the Operations Console UI provides a way to quickly validate your results after the fact.

Six cmdlets you will need when working with overrides on rules and monitors are:

  • Get-SCOMMonitor – retrieves monitors based on -displayname or other search filters you apply
  • Get-SCOMRule – retrieves monitors based on -displayname or other search filters you apply
  • Enable-SCOMRule – Enables the rule or rules that match your search criteria.
  • Enable-SCOMMonitor – Enables the monitor or monitors that match your search criteria.
  • Disable-SCOMRule – Disables the rule or rules that match your search criteria.
  • Disable-SCOMMonitor – Disables the monitor or monitors that match your search criteria.

Let’s take a quick look at these cmdlets in action to better understand how they work and how you can verify the results of your scripts.

Disabling Rules in Bulk (sample script)

To disable rules in bulk (that target SQL DB Engine and contain “*events/sec*” in their name, you’ll need a script that performs the following steps:

  • Retrieve the management pack in which to store the overrides
  • Retrieve the class that will be targeted by the override
  • Retrieve the rules or monitors that will be disabled
  • Disable the rule or monitor

Here is the sample that disables all rules matching the “*events/sec*” filter.

NOTE: You may have already guessed that you’ll need to carefully check which rules are returned by the Get-SCOMRule line and what class they target to ensure you retrieve the correct class with Get-SCOMClass. Just to be safe, you could actually find the target of the rule using Get-SCOMRule and pass that to Get-SCOMClass.

Checking Your Work

You can view your results in the Operations Console in the Authoring space in the Overrides node.

image

 

Re-enabling Disabled Rules (sample script)

To re-enable the same rules, you can use the Enable-SCOMRule cmdlet

Checking Your Work

Again, you can view your results in the Operations Console in the Authoring space in the Overrides node.

image

Additional Resources

You’ll find a growing number of System Center, Cloud and PowerShell resources here on SCC in the “Master Collection of System Center PowerShell” and elsewhere. A few related Operations Manager 2012 Command Shell articles

OpsMgr 2012: Group Maintenance Mode via PowerShell (the way it should be)

OpsMgr 2012: Running a Task in Bulk Using PowerShell

OpsMgr 2012: Automating Agent Discovery and Deployment with PowerShell [sample script]

OpsMgr 2012: Identifying Computers in Active Directory without an OpsMgr Agent Installed [sample script]

OpsMgr 2012 Quick Tip: Finding servers experiencing the most heartbeat failures with PowerShell

2 thoughts on “OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell

  1. Chris

    Just a little enhancement to your script. The TXT file should be a list of GUIDs for each rule/monitor, like this:
    34ec4795-282a-dc8f-6088-08843e018097
    06f5abed-f779-bd89-c9e0-12a863ecb60f
    414d8d85-6a20-597d-40a1-a424d4243829
    2ca86fbf-749e-7025-a055-0a1527de69eb

    Script:

    $Disablerules = Get-Content .\WindowsClustering2003.txt

    $MP = get-scommanagementpack -displayName Tgt-OR-Stability-WindowsClustering2003

    foreach ($rulename in $disablerules)
    {
    write-host “working on: ” $rulename
    $Rule = get-scomrule -Id $rulename
    #$Class = get-scomclass -ID (get-scomrule -displayname $rulename | select *).Target.Id.guid
    $Class = get-scomclass -ID ($Rule).Target.Id.guid
    Disable-SCOMRule -Class $Class -Rule $Rule -ManagementPack $MP -Enforce
    }

  2. Pingback: OpsMgr 2012: Disabling Rules and Monitors in Bulk in PowerShell | Hi!Tea

Leave a Reply

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