JAMA00

SCOM 2007 R2

Setting an override on a rule with PowerShell (OpsMgr snapin part 1: Set-OverrideRule)

Posted by MarcKlaver on March 26, 2010

We wanted to use PowerShell to create an override on specific rules. Since Google is your best friend, we started searching… And that was a disappointment. We only found a handful of links that stated that they did what we needed but only 1 that actually did more than just enable or disable a rule. This script on devcentral.f5.com was the only script that could do what we wanted. I used this as a starting point for our own cmdlets, that I could re-use in our PowerShell scripts. This blog will tell you how the snapin works and how to install it. The current version of the snapin can be downloaded here. There are two files available for download, one with the compiled .dll and help file (both x64 and x86) and one with the Visual Studio project and source code.

This snapin is still a work in progress (only the first cmdlet is now created), so I will create a blog when a cmdlet is finished. The current planning of cmdlets to write is:

  • Set-OverrideRule
  • Set-OverrideMonitor
  • Get-ObjectId
  • Enable-Monitor
  • Disable-Monitor
  • Enable-Rule
  • Disable-Rule
  • Get-ParameterMonitor
  • Get-ParamaterRule

Installing the snapin

To install the snapin, save the appropriate version (x64 or x86) to a directory of choice and execute from that directory:

%SystemRoot%\Microsoft.NET\Framework64\v2.0.50727\installutil.exe mkrOpsMgr.dll

Note that you must open the cmd.exe with “elevated” rights and that this is for the x64 version of the snapin. Now that the snapin is registered, you can load the snapin  by executing

add-pssnapin mkrOpsMgr

Set-OverrideRule

Now that the snapin is loaded, the cmdlet is available for use. Inside a PowerShell prompt run the

get-help Set-OverrideRule –full

command for the help file of the cmdlet. The easiest way to show you how this cmdlet works, is giving an example. The next example will override the rule “Collect Database Free Space (%)” from the SQL 2005 management pack for a specific server in my environment.

image

The example will override the “Frequency (seconds)” parameter and set it’s value to 5555.

image

Set-OverrideRule -RootManagementServer “RMS01” -ManagementPack $mp -ClassCriteria “DisplayName=’SQL 2005 DB'” -RuleCriteria “DisplayName=’Collect Database Free Space (%)'” -Parameter “IntervalSeconds” -Value “5555” -Target “f846dad3-c816-6e78-d29f-f4df1975cfee”

Oops, that looks overcomplicated! But don’t worry, it all makes sense 🙂

  • -RootManagementServer – The easy one, this is the name of the root management server. We need this to connect to the SDK service on this root management server.
  • -ManagementPack – This is the management pack that will be used to store the override. This management pack must exist, the cmdlet will not generate a new management pack. The value has to be an object, so you should retrieve a variable to this object with the get-managementpack cmdlet: $mp = get-managementpack | where {$_.Name -eq “jamaOverrideRuleTest”} And of course it needs to be an unsealed management pack, since we are going to write into this management pack.
  • -ClassCriteria – This is a string, with the criteria to select the class (object / target) in which the rule is defined. This should return a single class. If multiple classes are returned, an exception is generated. The format of the string is explained in this msdn article.
  • -RuleCriteria – A string with criteria, but this time it is used to select the rule we want to override. Again it must result in a single rule or an exception will be generated. The format of this string is explained in this msdn article.
  • -Parameter – This is the actual parameter we want to override in the rule (IntervalSeconds in this example). Note that the Enabled parameter can not be set with this cmdlet, I will create a separate cmdlet for the enabled parameter (which is actually a property).
  • -Value The value we want for the override.
  • -Target – This is the GUID of an explicit object (db, server, group, etc) as a string. When this value is given, the override will be set for this object only. Otherwise the override will be set for the rule.

Ok, great but wait…… How do I know which class and rule criteria to use and how can I find the parameter name??

The class criteria can be easily found in the GUI. If you use the “DisplayName”=” criteria, the class is the “Rule target” from the GUI.

image

And the rule criteria can be found also with the “DisplayName=” criteria, it is the rule name of the rule:

image

Don’t you love all those different names for the same object 🙂 ?

The only tricky one is the actual parameter, you have to look into the management pack itself to find the correct name. First find the Rule that corresponds with the display name:

image

The DisplayString element id, gives you the ID of the rule. Searching for that rule gives you:

image

Here you need the TypeID of the data source, which in turn will give you all available parameter names:

image

And that’s where you can find the required names for the parameter you are allowed to set. Or you must wait for the cmdlet Get-ParameterRule to be written 🙂

One Response to “Setting an override on a rule with PowerShell (OpsMgr snapin part 1: Set-OverrideRule)”

  1. Pixel said

    Doesnt work for me..
    I’ve tried many ways, with variables or without, i put exact displaynames, tried with $target or without, same.

    It always gives me:
    Microsoft.EnterpriseManagement.Common.InvalidCriteriaException: The criteria used fo
    r query has an invalid character or invalid keyword. The following parse error was r
    eturned: Parse error before 2007 —> Microsoft.EnterpriseManagement.Common.QueryGra
    mmarException: Parse error before 2007
    at Microsoft.EnterpriseManagement.Mom.QueryGrammar.QueryGrammarYaccClass.error(In
    t32 q_state, SSLexLexeme q_look)
    at Microsoft.EnterpriseManagement.Mom.QueryGrammar.SSVParseLib.SSYacc.doError()
    at Microsoft.EnterpriseManagement.Mom.QueryGrammar.SSVParseLib.SSYacc.parse()
    at Microsoft.EnterpriseManagement.Mom.QueryGrammar.QueryGrammarParser.GetCriteria
    Xml(String query)
    at Microsoft.EnterpriseManagement.Common.QueryCriteria.GetParseTree(String criter
    ia)
    — End of inner exception stack trace —
    at Microsoft.EnterpriseManagement.Common.QueryCriteria.GetParseTree(String criter
    ia)
    at Microsoft.EnterpriseManagement.Common.QueryCriteria.ParseCriteria(MonitoringCl
    ass monitoringClass, Boolean validateProperties)
    at Microsoft.EnterpriseManagement.Configuration.MonitoringClassCriteria..ctor(Str
    ing criteria)
    at mkrOpsMgr.SetRuleOverride.ProcessRecord()

    Example:
    $mp2 = get-managementpack |?{$_.Name -like “*my*test*mp*”};
    set-ruleoverride -RootManagementServer “mysrvname” -ManagementPack $mp2 -ClassCriteria DisplayName=”Exchange 2007 Hub Transport Role” -RuleCriteria “DisplayName=’The AD RMS Prelicensing agent failed to retrieve a license because recipient account(s) where not configured properly. Contact the AD RMS administrator.’” -Parameter “Severity” -Value “2”

Leave a comment