What Rules My Class?

There have been a few questions regarding how to enumerate the rules targeting a class.

Here is a script you can save as a file. I named the script get-rulesforclass.ps1

param ([String] $className)

$class = get-monitoringclass | where {$_.Name -eq $className}

if ($class -eq $null)
 throw "Class '$className' not found.";

if ($class -is [Array])
 throw "More than one class was found with name '$className'.";

write-host $class

get-rule | where {$_.Target.Id -eq $class.Id}

Pass the name of the class to the script.

get-rulesforclass.ps1 Microsoft.Windows.Computer

The Target property of the rule is where most people get stuck because it is not clear that you must refer to the Id property off of the target property to perform the comparison against the class's Id.

This is the final blog post to the System Center Operations Manager Command Shell blog. I will be changing my focus and no longer have time to properly contribute to this blog. As this is the last post I will not longer be taking questions or comments. I wish you all the best of luck in your scripting endeavors.


Roger Sprague