JAMA00

SCOM 2007 R2

Setting an override on a rule with PowerShell (OpsMgr snapin part 3)

Posted by MarcKlaver on May 12, 2010

A few examples on how to use the two cmdlets.

To try the cmdlets, type:

add-pssnapin mkropsmgr

This command adds the PowerShell snapin. This is required to use the cmdlets. You should only have to use this once in every session you run.

Get-RuleParameter -ClassCriteria "DisplayName like ‘%’" -RuleCriteria "DisplayName like ‘%’" –Verbose

This command will show you all overridable parameters from all rules. If you want to see the whole output, you should be patient 🙂 This command also needs to be run on the RMS server, since it will default to the “localhost” value to connect to the SDK service and the user running the command must have sufficient privileges to query the SCOM environment.

Get-RuleParameter -RootManagementServer "RMS01" -Credential $myCred -ClassCriteria "DisplayName like ‘SQL%’" -RuleCriteria "DisplayName like ‘Collect%’" –Verbose

This command will show you all overrideable parameters of all classes, whose display name starts with “SQL” and for all rules whose display name start with “Collect”.  The command will also try to connect to the RMS called “RMS01” and will ask for your credentials to use for connecting to this RMS. And finally it uses the –Verbose switch, to show additional information about the progress of the command.

add-pssnapin mkrOpsMgr

add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";

set-location "OperationsManagerMonitoring::";

$con = new-managementGroupConnection -ConnectionString:"RMS01" -Credential $myCred;

$mp = get-managementpack | where {$_.Name -eq "mpTestRuleOverride"}

Set-RuleOverride -ManagementPack $mp -ClassCriteria "DisplayName=’SQL 2005 DB’" -RuleCriteria "DisplayName=’Collect Database Free Space (%)’" -Parameter "Enabled" -Value "False" -Verbose –Enforce

These commands will load both the mkrOpsMgr and the Microsoft Operations Manager snapin followed  by a connection to the SDK on the server called “RMS01” (it will ask for credentials). It will retrieve the object for the “mpTestRuleOverride” management pack (which must exist) and will disable the rule with DisplayName “Collect Databse Free Space (%)” form the class with the DisplayName “SQL 2005 DB”. This is done by setting the parameter “Enabled” to “False”. This override is enforced with the –Enforce switch.

add-pssnapin mkrOpsMgr

add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";

set-location "OperationsManagerMonitoring::";

$con = new-managementGroupConnection -ConnectionString:"RMS01" -Credential $myCred;

$mp = get-managementpack | where {$_.Name -eq "mpTestRuleOverride"}

Set-RuleOverride -RootManagementServer "RMS01" -Credential $myCred -ManagementPack $mp -ClassCriteria "DisplayName=’SQL 2005 DB’" -RuleCriteria "DisplayName=’Collect Database Free Space (%)’" -DataSource "DS" -Parameter "IntervalSeconds" -Value "7777"

These commands will override the rule “Collect Database Free Space (%)” from the class “SQL 2005 DB” and set the value for the “IntervalSeconds” parameter to 7777. Note that running these command a second time, will generate an error indicating there is an override conflict on the rule. You can use the override name shown by the error to change the existing override, using the –OverrideId parameter of the Set-OverrideRule cmdlet.

Running this command the second time on my system, resulted in the error shown below:

: Verification failed with [1] errors:
——————————————————-
Error 1:
: Failed to verify Override [mkrOpsMgr.SetOverrideRule.0888eee2d8754f47820bac3e7887d7d5].
Override [mkrOpsMgr.SetOverrideRule.0888eee2d8754f47820bac3e7887d7d5] is a duplicate to Override [mkrOpsMgr.SetOverrideRule.9415ca506dd540d683c907bbdf1062aa] de
fined within the same ManagementPack. Please remove any one of the duplicate overrides.
——————————————————-

Failed to verify Override [mkrOpsMgr.SetOverrideRule.0888eee2d8754f47820bac3e7887d7d5].Override [mkrOpsMgr.SetOverrideRule.0888eee2d8754f47820bac3e7887d7d5] is
a duplicate to Override [mkrOpsMgr.SetOverrideRule.9415ca506dd540d683c907bbdf1062aa] defined within the same ManagementPack. Please remove any one of the duplic
ate overrides.

The blue OverrideId is the Id generated by the cmdlet when it was run for the second time. The red OverrideId is the existing one in the management pack. If you need to change an existing override, you should supply the existing OverrideId to the cmdlet:

add-pssnapin mkrOpsMgr

add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";

set-location "OperationsManagerMonitoring::";

$con = new-managementGroupConnection -ConnectionString:"RMS01" -Credential $myCred;

$mp = get-managementpack | where {$_.Name -eq "mpTestRuleOverride"}

Set-RuleOverride -RootManagementServer "RMS01" -Credential $myCred -ManagementPack $mp -ClassCriteria "DisplayName=’SQL 2005 DB’" -RuleCriteria "DisplayName=’Collect Database Free Space (%)’" -DataSource "DS" -Parameter "IntervalSeconds" -Value "8888" -overrideid "mkrOpsMgr.SetOverrideRule.9415ca506dd540d683c907bbdf1062aa"

These commands will now set the same override to the new value of 8888

I now realize I have not implemented a method to remove an override, so a new version will be build 🙂

Advertisements

3 Responses to “Setting an override on a rule with PowerShell (OpsMgr snapin part 3)”

  1. Marc Klaver said

    Ok, I know it has been a while, but there is some progress (I need to do a lot of testing before publishing). But unfortunately priorities have changed, so developing this will go slowly.

  2. Simon Jameson said

    Hi, maybe you can help. I’m trying to set the severity and priority for many rules in our environment. it sounds like this tool can help but i have been unable to get it to work

    >Get-RuleParameter -ClassCriteria “DisplayName=’Storage (ProLiant SNMP)'” -RuleCrite
    ria “DisplayName like ‘%ATA RAID%'” -Verbose
    VERBOSE: Connected to the SDK service on server: localhost
    VERBOSE: Searching class Storage (ProLiant SNMP)

    ClassName : Storage (ProLiant SNMP)
    RuleName : ATA RAID Logical Drive degraded.
    DisplayName : Severity
    Name : Severity
    Type : int
    Selector : $Config/Severity$
    Description :

    ClassName : Storage (ProLiant SNMP)
    RuleName : ATA RAID Logical Drive degraded.
    DisplayName : Priority
    Name : Priority
    Type : int
    Selector : $Config/Priority$
    Description :

    …..

    $mp = get-managementpack | where {$_.displayname -eq “HP Proliant overrides”}

    Set-RuleOverride -RootManagementServer “TLMAWFCPD0008” -ManagementPack $mp -ClassCriteria “DisplayName=’Storage (ProLiant SNMP)'” -RuleCriteria “DisplayName=’ATA RAID Logical Drive degraded.'” -Parameter “Severity” -Value “2”

    : Verification failed with [2] errors:
    ——————————————————-
    Error 1:
    : Failed to verify Override [mkrOpsMgr.SetOverrideRule.2b91a0fe97ea459ca281fb17b
    80130a7].
    Cannot find OverridableParameter with name [Severity] defined on [Microsoft.Wind
    ows.EventProvider]
    ——————————————————-
    Error 2:
    : Failed to verify Override [mkrOpsMgr.SetOverrideRule.2b91a0fe97ea459ca281fb17b
    80130a7].
    Cannot find OverridableParameter with name [Severity] defined on [Microsoft.Wind
    ows.EventProvider]
    ——————————————————-

    Failed to verify Override [mkrOpsMgr.SetOverrideRule.2b91a0fe97ea459ca281fb17b80
    130a7].Cannot find OverridableParameter with name [Severity] defined on [Microso
    ft.Windows.EventProvider]

    any idea why it is unable to find Severity when Get-RuleParameter cleared returns the parameter??

  3. Simon Jameson said

    i meant to write at the bottom – any idea why it is unable to find Severity when Get-RuleParameter clearly returns the parameter??

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: