<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.technet.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>BWren's Management Space : Command Shell</title><link>http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx</link><description>Tags: Command Shell</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Programmatically Creating Groups</title><link>http://blogs.technet.com/brianwren/archive/2008/11/18/programmatically-creating-groups.aspx</link><pubDate>Tue, 18 Nov 2008 11:04:27 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3155696</guid><dc:creator>Brian Wren</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.technet.com/brianwren/comments/3155696.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=3155696</wfw:commentRss><description>&lt;p&gt;Well, it looks from my last post that I took about a eight month hiatus from the blog.&amp;#160; Fortunately, I've been doing a bunch of OpsMgr in that time, so I have a bunch of content to get out here.&amp;#160; Just a matter of taking the time to write it up.&lt;/p&gt;  &lt;p&gt;The one I'll go with first is programmatically creating groups.&amp;#160; Now creating a single group is pretty easy in the Operations Console, so creating a single one from a command line isn't going to get anyone excited.&amp;#160; What is exciting though is if you have a bunch of groups to create - especially if several of these are subgroups.&lt;/p&gt;  &lt;p&gt;I'll leave you to figure out the complexity of providing a list of groups - maybe reading from a text file or something.&amp;#160; That's just straight PowerShell work.&amp;#160; What I will give you though is the code to create a new group.&amp;#160; You should be able to use this base code to do whatever complex and repetitive group creation that you might need.&lt;/p&gt;  &lt;p&gt;First of all, there is no cmdlet to create a group.&amp;#160; You're going to have to manually create a Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup object, set its properties, and then save it to the management group using the InsertCustomMonitoringObjectGroup method on the management group.&amp;#160; That part's easy.&amp;#160; It will be when I give you the code in a minute anyway.&amp;#160; The tough part of the exercise is setting the membership formula, and we need to go through that before we get into the code.&lt;/p&gt;  &lt;h2&gt;Membership Formula&lt;/h2&gt;  &lt;p&gt;The membership formula is an XML expression defining the logic for what objects should be members of the group.&amp;#160; The easiest way to figure out how to build this formula is to configure a group using the dialog box in the Operations Console and then copy out the resulting XML.&amp;#160; There are a couple of things you need to know about this though,&amp;#160; so let me provide a bit of explanation and a couple of examples.&lt;/p&gt;  &lt;p&gt;When you export the management pack, you'll find the membership rule in the discovery for the group.&amp;#160; It might take you a little bit of searching through the different discoveries if you aren't familiar with the XML schema of a management pack, but it shouldn't take too long.&amp;#160; A typical discovery will look something like the XML below.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&amp;lt;Discovery ID=&lt;span class="str"&gt;&amp;quot;UINameSpace9e378de9416945c4820c4cacfd0475fa.Group.DiscoveryRule&amp;quot;&lt;/span&gt; Enabled=&lt;span class="str"&gt;&amp;quot;true&amp;quot;&lt;/span&gt; Target=&lt;span class="str"&gt;&amp;quot;UINameSpace9e378de9416945c4820c4cacfd0475fa.Group&amp;quot;&lt;/span&gt; ConfirmDelivery=&lt;span class="str"&gt;&amp;quot;false&amp;quot;&lt;/span&gt; Remotable=&lt;span class="str"&gt;&amp;quot;true&amp;quot;&lt;/span&gt; Priority=&lt;span class="str"&gt;&amp;quot;Normal&amp;quot;&lt;/span&gt;&amp;gt; 
  &amp;lt;Category&amp;gt;Discovery&amp;lt;/Category&amp;gt; 
  &amp;lt;DiscoveryTypes&amp;gt; 
    &amp;lt;DiscoveryRelationship TypeID=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt; /&amp;gt; 
  &amp;lt;/DiscoveryTypes&amp;gt; 
  &amp;lt;DataSource ID=&lt;span class="str"&gt;&amp;quot;GroupPopulationDataSource&amp;quot;&lt;/span&gt; TypeID=&lt;span class="str"&gt;&amp;quot;SystemCenter!Microsoft.SystemCenter.GroupPopulator&amp;quot;&lt;/span&gt;&amp;gt; 
    &amp;lt;RuleId&amp;gt;$MPElement$&amp;lt;/RuleId&amp;gt; 
    &amp;lt;GroupInstanceId&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;UINameSpace9e378de9416945c4820c4cacfd0475fa.Group&amp;quot;&lt;/span&gt;]$&amp;lt;/GroupInstanceId&amp;gt; 
    &amp;lt;MembershipRules&amp;gt; 
      &amp;lt;MembershipRule&amp;gt; 
        &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroup&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
        &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
        &amp;lt;IncludeList&amp;gt; 
          &amp;lt;MonitoringObjectId&amp;gt;d47ea9a0-a039-d399-bec3-4b305269b57e&amp;lt;/MonitoringObjectId&amp;gt; 
        &amp;lt;/IncludeList&amp;gt; 
      &amp;lt;/MembershipRule&amp;gt; 
    &amp;lt;/MembershipRules&amp;gt; 
  &amp;lt;/DataSource&amp;gt; 
&amp;lt;/Discovery&amp;gt;&lt;/pre&gt;

&lt;p&gt;The only part you want is the MembershipRules section, and that’s what I’ll describe below.&lt;/p&gt;

&lt;h2&gt;&lt;/h2&gt;

&lt;h2&gt;Membership Formula Examples&lt;/h2&gt;

&lt;h3&gt;&lt;/h3&gt;

&lt;p&gt;First, let's look at a typical dynamic membership.&amp;#160; The following dialog box shows a criteria that you might create.&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_6.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_thumb_2.png" width="433" height="353" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;That logic would translate to the following membership rule which could be used as is.&amp;#160; There are no GUIDs here to worry about.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;MembershipRule&amp;gt; 
  &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;Windows!Microsoft.Windows.Computer&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
  &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
  &amp;lt;Expression&amp;gt; 
    &amp;lt;And&amp;gt; 
      &amp;lt;Expression&amp;gt; 
        &amp;lt;RegExExpression&amp;gt; 
          &amp;lt;ValueExpression&amp;gt; 
            &amp;lt;Property&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;Windows!Microsoft.Windows.Computer&amp;quot;&lt;/span&gt;]/PrincipalName$&amp;lt;/Property&amp;gt; 
          &amp;lt;/ValueExpression&amp;gt; 
          &amp;lt;Operator&amp;gt;MatchesWildcard&amp;lt;/Operator&amp;gt; 
          &amp;lt;Pattern&amp;gt;lgb*&amp;lt;/Pattern&amp;gt; 
        &amp;lt;/RegExExpression&amp;gt; 
      &amp;lt;/Expression&amp;gt; 
      &amp;lt;Expression&amp;gt; 
        &amp;lt;RegExExpression&amp;gt; 
          &amp;lt;ValueExpression&amp;gt; 
            &amp;lt;Property&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;Windows!Microsoft.Windows.Computer&amp;quot;&lt;/span&gt;]/IPAddress$&amp;lt;/Property&amp;gt; 
          &amp;lt;/ValueExpression&amp;gt; 
          &amp;lt;Operator&amp;gt;MatchesWildcard&amp;lt;/Operator&amp;gt; 
          &amp;lt;Pattern&amp;gt;10.1.*&amp;lt;/Pattern&amp;gt; 
        &amp;lt;/RegExExpression&amp;gt; 
      &amp;lt;/Expression&amp;gt; 
    &amp;lt;/And&amp;gt; 
  &amp;lt;/Expression&amp;gt; 
&amp;lt;/MembershipRule&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;How about a group with explicit members?&amp;#160; Now this is probably a bad example, because you probably won't pragmatically be creating groups with explicit members, but it is possible.&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_8.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_thumb_3.png" width="434" height="415" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;This generates the following membership rule which includes GUIDs.&amp;#160; These GUIDs really can't be swapped out though since they refer to specific objects.&amp;#160; If you were to programmatically&amp;#160; create something like this, you would presumably use Get-MonitoringObject in Command Shell to get the GUID of the object you're interested in and then add it to the XML.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;MembershipRule&amp;gt; 
  &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SystemCenter!Microsoft.SystemCenter.ManagedComputer&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
  &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
  &amp;lt;IncludeList&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;b3e9befe-173b-78a2-3e41-e19ecb58d9d5&amp;lt;/MonitoringObjectId&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;0852e1eb-f854-eb88-2f7d-a1bb0794d18f&amp;lt;/MonitoringObjectId&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;6e813ffe-2267-a191-ccbb-566d4ddf95bc&amp;lt;/MonitoringObjectId&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;98e3ee12-54c0-f14c-506c-4113bb8f1dcb&amp;lt;/MonitoringObjectId&amp;gt; 
  &amp;lt;/IncludeList&amp;gt; 
&amp;lt;/MembershipRule&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Subgroups are something you very well might want to use.&amp;#160; One use of programmatically creating groups is to create a complex group structure which may contain several levels of different groups.&lt;/p&gt;

&lt;p align="center"&gt;&lt;a href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_10.png"&gt;&lt;img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" border="0" alt="image" src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/ProgrammaticallyCreatingGroups_127CF/image_thumb_4.png" width="445" height="425" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;This would generate the following XML, and in this case we would want to swap out that GUID which refers to the subgroup (Sample Group - Level 2 in the example).&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;MembershipRule&amp;gt; 
  &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroup&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
  &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
  &amp;lt;IncludeList&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;e499513e-4e67-142e-f1f6-53b24b5195bb&amp;lt;/MonitoringObjectId&amp;gt; 
  &amp;lt;/IncludeList&amp;gt; 
&amp;lt;/MembershipRule&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;This would work better with the following.&amp;#160; The end result is the same since we'll still end up with the GUID of the subgroup.&amp;#160; but this example could be installed in other management groups and would make a lot more sense when working with code.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;MembershipRule&amp;gt; 
  &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroup&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
  &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
  &amp;lt;IncludeList&amp;gt; 
    &amp;lt;MonitoringObjectId&amp;gt;$MPElement[Name=&lt;span class="str"&gt;'bwren.GroupDemo.SampleGroupLevel2'&lt;/span&gt;]$&amp;lt;/MonitoringObjectId&amp;gt; 
  &amp;lt;/IncludeList&amp;gt; 
&amp;lt;/MembershipRule&amp;gt;&lt;/pre&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;Finally, we need to talk about empty groups since this is very common situation when programmatically creating groups.&amp;#160; You may automate the creation of a large group structure relying on users to add objects to these groups through the Operations Console once the management pack is loaded.&amp;#160; Empty groups have a very specific structure which is below.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;    &amp;lt;MembershipRule Comment=&lt;span class="str"&gt;&amp;quot;EMPTY_RULE_8eadaced-59c8-4ebc-a4e4-b8428a374442&amp;quot;&lt;/span&gt;&amp;gt; 
      &amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SC!Microsoft.SystemCenter.AllComputersGroup&amp;quot;&lt;/span&gt;]$&amp;lt;/MonitoringClass&amp;gt; 
      &amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&lt;span class="str"&gt;&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;&lt;/span&gt;]$&amp;lt;/RelationshipClass&amp;gt; 
      &amp;lt;Expression&amp;gt; 
        &amp;lt;SimpleExpression&amp;gt; 
          &amp;lt;ValueExpression&amp;gt; 
            &amp;lt;Value&amp;gt;True&amp;lt;/Value&amp;gt; 
          &amp;lt;/ValueExpression&amp;gt; 
          &amp;lt;Operator&amp;gt;Equal&amp;lt;/Operator&amp;gt; 
          &amp;lt;ValueExpression&amp;gt; 
            &amp;lt;Value&amp;gt;False&amp;lt;/Value&amp;gt; 
          &amp;lt;/ValueExpression&amp;gt; 
        &amp;lt;/SimpleExpression&amp;gt; 
      &amp;lt;/Expression&amp;gt; 
    &amp;lt;/MembershipRule&amp;gt; &lt;br /&gt;&lt;/pre&gt;

&lt;p&gt;As you can see, the basic logic is to check if True equals False.&amp;#160; Since this will obviously never be a true statement, we have no objects that match the criteria.&amp;#160; The other thing you need though is the comment with that specific string on the MembershipRule tab.&amp;#160; There’s no real value in going into the background on that.&amp;#160; Just know that you need it.&amp;#160; If you don’t include it, the group will get created, but you’ll get a pretty ugly error when you try to modify the membership of that group from the Operations Console. &lt;/p&gt;

&lt;h2&gt;Management Pack Aliases &lt;/h2&gt;

&lt;p&gt;If you aren’t familiar with management pack aliases, they are separated from management object names with a ! in all the examples above.&amp;#160; An alias is required if you are referring to an object in another management pack.&amp;#160; The alias to that management pack must be in the References section of the management pack containing your group.&amp;#160; In the examples above, you can see the alias SCIG which refers to the System Center Instances Group management pack.&amp;#160; As such, the Reference section would need to contain the following entry.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;Reference Alias=&lt;span class="str"&gt;&amp;quot;SCIG&amp;quot;&lt;/span&gt;&amp;gt; 
  &amp;lt;ID&amp;gt;Microsoft.SystemCenter.InstanceGroup.Library&amp;lt;/ID&amp;gt; 
  &amp;lt;Version&amp;gt;6.0.6278.0&amp;lt;/Version&amp;gt; 
  &amp;lt;PublicKeyToken&amp;gt;31bf3856ad364e35&amp;lt;/PublicKeyToken&amp;gt; 
&amp;lt;/Reference&amp;gt;&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;

&lt;p&gt;Your management pack might use a different alias for Microsoft.SystemCenter.InstanceGroup.Library.&amp;#160; I just created a new management pack with the Operations Console, and it used MicrosoftSystemCenterInstanceGroupLibrary6164070. Obviously, you will need to use whatever alias your management pack is using.&amp;#160; I have some code that will figure out what alias is being used for a particular management pack, but that will have to wait for a later post.&lt;/p&gt;

&lt;h2&gt;Creating the Group&lt;/h2&gt;

&lt;p&gt;Now that you know how to create the formula, you need the code to create the group.&amp;#160; We’re using the InsertCustomMonitoringObjectGroup method of the ManagementPack class.&amp;#160; We need to pass that a CustomMonitoringObjectGroup which is created with a group name, a group display name, and a formula.&amp;#160; The group name is created from a combination of a namespace and a name.&amp;#160; The namespace acts as the standard prefix for all objects in the management pack.&amp;#160; It will append that the the group name that we specify to build a complete name.&amp;#160; In the example below, I’m using a namespace of bwren.Groups and a group name of Gargantua.&amp;#160; The full name of the resulting group will be bwren.Groups.Gargantua.&lt;/p&gt;

&lt;p&gt;With all that explanation, I’ll let the following code speak for itself.&amp;#160; This example creates an empty group, but all you would need to do to create a different membership rule is to replace the $formula variable with one of the examples above.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$mpName = &lt;span class="str"&gt;'bwren.Groups'&lt;/span&gt; 
$namespace = &lt;span class="str"&gt;'bwren.groups'&lt;/span&gt; 
$groupName = &lt;span class="str"&gt;'gargantua'&lt;/span&gt; 
$groupDisplayName = &lt;span class="str"&gt;'Gargantua'&lt;/span&gt;


$formula =  &lt;span class="str"&gt;'&amp;lt;MembershipRule Comment=&amp;quot;EMPTY_RULE_8eadaced-59c8-4ebc-a4e4-b8428a374442&amp;quot;&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;MonitoringClass&amp;gt;$MPElement[Name=&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroup&amp;quot;]$&amp;lt;/MonitoringClass&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;RelationshipClass&amp;gt;$MPElement[Name=&amp;quot;SCIG!Microsoft.SystemCenter.InstanceGroupContainsEntities&amp;quot;]$&amp;lt;/RelationshipClass&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;Expression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;SimpleExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;ValueExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;Value&amp;gt;True&amp;lt;/Value&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;/ValueExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;Operator&amp;gt;Equal&amp;lt;/Operator&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;ValueExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;Value&amp;gt;False&amp;lt;/Value&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;/ValueExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;/SimpleExpression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;/Expression&amp;gt;'&lt;/span&gt; + ` 
            &lt;span class="str"&gt;'&amp;lt;/MembershipRule&amp;gt;'&lt;/span&gt; 

$group = New-Object Microsoft.EnterpriseManagement.Monitoring.CustomMonitoringObjectGroup($namespace,$groupName,$groupDisplayName,$formula) 
$mp = Get-ManagementPack -name $mpName 
$mp.InsertCustomMonitoringObjectGroup($group)&lt;/pre&gt;
&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;style type="text/css"&gt;
.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }&lt;/style&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3155696" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>One more MMS Follow Up</title><link>http://blogs.technet.com/brianwren/archive/2008/05/07/one-more-mms-follow-up.aspx</link><pubDate>Wed, 07 May 2008 19:26:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3051661</guid><dc:creator>Brian Wren</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/brianwren/comments/3051661.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=3051661</wfw:commentRss><description>&lt;P&gt;As I ran out of time in the MMS session, I quickly showed a script that listed all performance monitors and their thresholds.&amp;nbsp; This came from the &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyId=DB3E6FB0-880E-4086-BDEF-1D45327F6A84&amp;amp;displaylang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyId=DB3E6FB0-880E-4086-BDEF-1D45327F6A84&amp;amp;displaylang=en"&gt;SharePoint Portal Server Management Pack Guide&lt;/A&gt;.&amp;nbsp; The only change I made was to comment out the command to export the results to a csv so the information would come scrolling across the screen.&amp;nbsp; I attached the script with that small change to this post.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3051661" width="1" height="1"&gt;</description><enclosure url="http://blogs.technet.com/brianwren/attachment/3051661.ashx" length="1628" type="application/octet-stream" /><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>Monitoring Object Properties</title><link>http://blogs.technet.com/brianwren/archive/2008/05/03/monitoring-object-properties.aspx</link><pubDate>Sun, 04 May 2008 00:10:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3049392</guid><dc:creator>Brian Wren</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/brianwren/comments/3049392.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=3049392</wfw:commentRss><description>&lt;P&gt;There has been some question about how to get properties for monitoring objects with Command Shell.&amp;nbsp; I wanted to go into this in my MMS session last week, but I already ran out of time just trying to cram in all the topics I did cover.&amp;nbsp; Shouldn't be too tough to explain it here though.&lt;/P&gt;
&lt;P&gt;If you use Get-MonitoringObject, you get a common set of properties for all objects.&amp;nbsp; Kind of like the following:&lt;/P&gt;&lt;PRE class=csharpcode&gt;PS Monitoring:\OpsMgr01
&amp;gt;$mc = get-monitoringClass -name Microsoft.Windows.Computer
&amp;gt;$mc | get-monitoringObject | where {$_.name &lt;SPAN class=preproc&gt;-match&lt;/SPAN&gt; &lt;SPAN class=str&gt;'web01'&lt;/SPAN&gt;} 

Id               : 0844f543-762c-5800-794c-a72a1823ea96
PathName         : web01.greengargantua.com
DisplayName      : web01.greengargantua.com
ManagementMode   :
ManagementGroup  : gaira
HealthState      : Success
OperationalState : 

PS Monitoring:\OpsMgr01
&amp;gt;$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database &lt;BR&gt;&amp;gt;$mc | get-monitoringObject | where {$_.name &lt;SPAN class=preproc&gt;-match&lt;/SPAN&gt; &lt;SPAN class=str&gt;'blob'&lt;/SPAN&gt;} &lt;BR&gt; 

Id               : dfd4fd2b-6c7f-6c9c-a1cd-4d074613e3fd
PathName         : opsmgr01.greengargantua.com%003bMSSQLSERVER%003ablob
DisplayName      : blob
ManagementMode   :
ManagementGroup  : gaira
HealthState      : Success
OperationalState : 
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;That example shows two objects that are completely different - a database and a computer - but we show an identical set of properties.&amp;nbsp; We know that there a bunch of properties unique to each of those classes, but where are they? 
&lt;P&gt;In order to display all properties for the object, you can use one of the Format CmdLets with * indicating you want all properties.&amp;nbsp; That results in the following:&amp;nbsp; &lt;PRE class=csharpcode&gt;PS Monitoring:\OpsMgr01
&amp;gt;$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database&lt;BR&gt;&amp;gt;$mc | get-monitoringObject | where {$_.name &lt;SPAN class=preproc&gt;-match&lt;/SPAN&gt; &lt;SPAN class=str&gt;'blob'&lt;/SPAN&gt;} | fl * 

PathName                                        : opsmgr01.bwren.com%003bMSSQLSERVER%003ablob
UniquePathName                                  : Microsoft.SQLServer.Database%003aopsmgr01.bwren.com%003bMSSQLSERVER%003bblob
[Microsoft.SQLServer.Database].DatabaseName     : blob
[Microsoft.SQLServer.Database].RecoveryModel    : FULL
[Microsoft.SQLServer.Database].DatabaseAutogrow : True
[Microsoft.SQLServer.Database].DatabaseSize     : 2
[Microsoft.SQLServer.Database].LogAutogrow      : True
[Microsoft.SQLServer.Database].Updateability    : READ_WRITE
[Microsoft.SQLServer.Database].UserAccess       : MULTI_USER
[Microsoft.SQLServer.Database].Collation        : SQL_Latin1_General_CP1_CI_AS
[Microsoft.SQLServer.Database].LogSize          : 1
[Microsoft.SQLServer.Database].Owner            : BWREN\Administrator
[System.Entity].DisplayName                     : blob
Name                                            : blob
Path                                            : opsmgr01.bwren.com;MSSQLSERVER
DisplayName                                     : blob
FullName                                        : Microsoft.SQLServer.Database:opsmgr01.bwren.com;MSSQLSERVER;blob
IsManaged                                       : True
LastModified                                    : 11/26/2007 7:07:20 AM
HealthState                                     : Success
StateLastModified                               : 5/1/2008 8:39:45 PM
IsAvailable                                     : True
AvailabilityLastModified                        : 5/3/2008 5:20:29 PM
InMaintenanceMode                               : False
MaintenanceModeLastModified                     : 5/1/2008 8:39:06 PM
MonitoringClassIds                              : {10c1c7f7-ba0f-5f9b-c74a-79a891170934, cae6be07-6483-361b-710f-c7612e29fa7b}
LeastDerivedNonAbstractMonitoringClassId        : 10c1c7f7-ba0f-5f9b-c74a-79a891170934
Id                                              : dfd4fd2b-6c7f-6c9c-a1cd-4d074613e3fd
ManagementGroup                                 : bwren
ManagementGroupId                               : 80342cfb-a3e1-aa59-7eac-cb5b5f167c38 
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;The properties specific to the individual class are preceded with the name of the class they came from surrounded by brackets.&amp;nbsp; I'll explain the details of that later.&amp;nbsp; For now, just know that you have to specify the entire thing to retrieve the property value.&amp;nbsp; Since PowerShell sees those brackets as special characters, you need to surround the entire property name with quotes.&amp;nbsp; &lt;PRE class=csharpcode&gt;&amp;gt;$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database&lt;BR&gt;&amp;gt;$mo = $mc | get-monitoringObject | where {$_.name &lt;SPAN class=preproc&gt;-match&lt;/SPAN&gt; &lt;SPAN class=str&gt;'blob'&lt;/SPAN&gt;}&lt;BR&gt;&amp;gt;$mo."[Microsoft.SQLServer.Database].LogAutogrow"
&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;That syntax can actually get tricky, and I'll be honest that I haven't figured out how to get it working in all cases.&amp;nbsp; The other approach you can use is the Get-MonitoringObjectProperty CmdLet.&amp;nbsp; The name property from that CmdLet will be the simple name of the property.&amp;nbsp; &lt;PRE class=csharpcode&gt;&amp;gt;$mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database &lt;BR&gt;&amp;gt;$mo = $mc | get-monitoringObject | where {$_.name &lt;SPAN class=preproc&gt;-match&lt;/SPAN&gt; &lt;SPAN class=str&gt;'blob'&lt;/SPAN&gt;} &lt;BR&gt;&amp;gt;$mo | get-monitoringObjectProperty | sort parentElement,name | ft parentElement,name,value 

ParentElement                         Name                      Value
-------------                         ----                      -----
Microsoft.SQLServer.Database          Collation                 SQL_Latin1_General_CP1_CI_AS
Microsoft.SQLServer.Database          DatabaseAutogrow          True
Microsoft.SQLServer.Database          DatabaseName              blob
Microsoft.SQLServer.Database          DatabaseSize              2
Microsoft.SQLServer.Database          LogAutogrow               True
Microsoft.SQLServer.Database          LogSize                   1
Microsoft.SQLServer.Database          Owner                     BWREN\Administrator
Microsoft.SQLServer.Database          RecoveryModel             FULL
Microsoft.SQLServer.Database          Updateability             READ_WRITE
Microsoft.SQLServer.Database          UserAccess                MULTI_USER
System.Entity                         DisplayName               blob

&lt;/PRE&gt;
&lt;P&gt;If you already know about the concept of base classes in OpsMgr, then you already know what that that ParentElement class is.&amp;nbsp; If not, let me provide a very brief description just so you at least have a little background information.If you want more details on this whole concept of class structures in OpsMgr, the &lt;A href="http://download.microsoft.com/download/7/4/d/74deff5e-449f-4a6b-91dd-ffbc117869a2/OM2007_AuthGuide.doc" mce_href="http://download.microsoft.com/download/7/4/d/74deff5e-449f-4a6b-91dd-ffbc117869a2/OM2007_AuthGuide.doc"&gt;Authoring Guide&lt;/A&gt; has complete documentation.&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;

&lt;P&gt;All classes in OpsMgr have a base class.&amp;nbsp; That base class may have a base class, and its base class may have a base class, etc.&amp;nbsp; All classes will eventually find their way up to System.Entity which is the only class with no base.&amp;nbsp; The object tree for the SQL 2005 Database class is shown below.&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/MonitoringObjectProperties_C7BC/image_6.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/MonitoringObjectProperties_C7BC/image_6.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=210 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/MonitoringObjectProperties_C7BC/image_thumb_2.png" width=451 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/MonitoringObjectProperties_C7BC/image_thumb_2.png"&gt;&lt;/A&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a class has properties associated with it, then any classes that inherit from it (ie. they use that class as their base class) inherit its properties and any properties along the class tree.&amp;nbsp; There are no properties explicitly assigned to SQL 2005 Database.&amp;nbsp; Instead, those properties you see (Collation, DatabaseAutogroup, etc) are defined on the SQL Database class.&amp;nbsp; As you might imagine, SQL 2000 Database inherits from that same class so it inherits the same properties as SQL Database.&lt;/P&gt;
&lt;STYLE type=text/css&gt;.csharpcode, .csharpcode pre
{
	font-size: small;
	color: black;
	font-family: consolas, "Courier New", courier, monospace;
	background-color: #ffffff;
	/*white-space: pre;*/
}
.csharpcode pre { margin: 0em; }
.csharpcode .rem { color: #008000; }
.csharpcode .kwrd { color: #0000ff; }
.csharpcode .str { color: #006080; }
.csharpcode .op { color: #0000c0; }
.csharpcode .preproc { color: #cc6633; }
.csharpcode .asp { background-color: #ffff00; }
.csharpcode .html { color: #800000; }
.csharpcode .attr { color: #ff0000; }
.csharpcode .alt 
{
	background-color: #f4f4f4;
	width: 100%;
	margin: 0em;
}
.csharpcode .lnum { color: #606060; }
&lt;/STYLE&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3049392" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>Setting Maintenance Mode from an Agent</title><link>http://blogs.technet.com/brianwren/archive/2008/05/01/setting-maintenance-mode-from-an-agent.aspx</link><pubDate>Fri, 02 May 2008 03:19:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:3048346</guid><dc:creator>Brian Wren</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/brianwren/comments/3048346.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=3048346</wfw:commentRss><description>&lt;P&gt;My apologies that I forgot to talk about this in my MMS session earlier today.&amp;nbsp; I did mention it to a couple of people after the session.&amp;nbsp; &lt;A href="http://derekhar.blogspot.com/" mce_href="http://derekhar.blogspot.com/"&gt;Derek Harkin&lt;/A&gt; came up with an interesting method for initiating maintenance mode from an agent.&amp;nbsp; No OpsMgr client of any kind required - just a simple script for the user to execute.&amp;nbsp; No need to reiterate the details here, have a look at &lt;A href="http://derekhar.blogspot.com/2008/02/initiate-maintenance-mode-from-agent-no.html" mce_href="http://derekhar.blogspot.com/2008/02/initiate-maintenance-mode-from-agent-no.html"&gt;Derek's blog entry&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=3048346" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>MMS Command Shell Presentation</title><link>http://blogs.technet.com/brianwren/archive/2008/03/11/mms-command-shell-presentation.aspx</link><pubDate>Tue, 11 Mar 2008 17:28:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2988208</guid><dc:creator>Brian Wren</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.technet.com/brianwren/comments/2988208.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=2988208</wfw:commentRss><description>&lt;P&gt;As promised, here are all the samples that I am showing in my MMS session on Command Shell.&amp;nbsp; There are also a several samples I'm planning on mentioning but won't have time to show.&amp;nbsp; Hope it's helpful.&lt;/P&gt;
&lt;P&gt;Given the length of the this, chances are pretty good that I have an error somewhere.&amp;nbsp; Please let me know if there's anything that doesn't work, if there's anything you think I forgot, or if you have any improvements to any of these scenarios.&amp;nbsp; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Management Groups&lt;/H1&gt;
&lt;P&gt;Add a management group connection:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; new-managementGroupConnection OpsMgr02&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=center mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Change your default management group connection:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; new-defaultManagementGroupConnection OpsMgr02 $true&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;View all current management group connections:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-ManagementGroupConnection&lt;/FONT&gt;&lt;/P&gt;
&lt;P align=left&gt;or&lt;/P&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; cd \&lt;BR&gt;&amp;gt; dir&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Management Packs&lt;/H1&gt;
&lt;P align=left&gt;Export a specific management pack (sealed or unsealed):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-managementPack -name Microsoft.SQLServer.2005.Monitoring | export-managementPack -path c:\mp&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Export all management packs in a management group:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-managementPack | export-managementPack -path c:\mp &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Install a management pack to multiple management groups:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; new-managementGroupConnection OpsMgr02&lt;BR&gt;&amp;gt; cd \&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;gt; install-managementPack c:\mp\Contoso.MyManagementPack.mp &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Export management pack from test environment, seal it,&amp;nbsp;and import to two production management groups:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; get-managementPack -name bwren.MMS | export-managementPack -path c:\mp&lt;BR&gt;&amp;gt; MPSeal.exe&amp;nbsp; Contoso.MyManagementPack.xml /I c:\mp /Keyfile c:\keys\contosoKeyPair.snk&amp;nbsp; /Company "Contoso"&lt;BR&gt;&amp;gt; new-managementGroupConnection ggOpsMgr01.greenGargantua.com&lt;BR&gt;&amp;gt; cd \ggOpsMgr01.greenGargantua.com&lt;BR&gt;&amp;gt; install-managementPack c:\mp\bwren.mms.xml&lt;BR&gt;&amp;gt; cd \OpsMgr01.bwren.com&lt;BR&gt;&amp;gt; get-managementGroupConnection | where {$_.managementServerName -eq 'ggOpsMgr01.greenGargantua.com'} | remove-managementGroupConnection&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;&lt;/H1&gt;
&lt;H1&gt;Agents&lt;/H1&gt;
&lt;P&gt;Install an agent on a single computer:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $ms = get-managementServer | where {$_.name -eq 'OpsMgr02.GreenGargantua.com'}&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&amp;gt; install-agentByName -name 'srv01' -managementServer $ms&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Install agents to a list of computers from a text file:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $ms = get-managementServer | where {$_.name -eq 'OpsMgr02.GreenGargantua.com'}&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&amp;gt; gc c:\scripts\agents.txt | foreach {install-agentByName -name $_ -managementServer $ms}&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Schedule install of agents to a list of computers from a text file.&amp;nbsp; &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Script: InstallAgents.ps1&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;param($file,$managementServer,$rmsServerName) &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";&lt;BR&gt;Set-Location "OperationsManagerMonitoring::";&lt;BR&gt;$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName&lt;BR&gt;Set-Location $rmsServerName &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;$ms = get-managementServer | where {$_.name -eq $managementServer}&lt;BR&gt;gc $file | foreach {install-agentByName -managementServer $ms -name $_}&lt;/FONT&gt;&lt;/P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Run from Task Scheduler:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "c:\scripts\InstallAgents.ps1" -file:'c:\scripts\computers.txt' -managementServer:OpsMgr02 -rmsServerName:'OpsMgr01' &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Discover all domain controllers and install an agent on each:&amp;nbsp; &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $ms = get-managementServer | where {$_.name -eq 'OpsMgr02.GreenGargantua.com'}&lt;BR&gt;&amp;gt; $discoveryConfig = new-ldapQueryDiscoveryCriteria -domain contoso.com -ldapQuery "(primaryGroupID=516)"&lt;BR&gt;&amp;gt; $discoveryResult = start-discovery -managementServer $ms -windowsDiscoveryConfiguration $discoveryConfig&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $installResult = install-agent -managementServer $ms -agentManagedComputer $discoveryResult.CustomMonitoringObjects&lt;BR&gt;&amp;gt; $installResult.MonitoringTaskResults&lt;/FONT&gt; &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Display the proxy setting for all agents with a particular string in the computer name:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-agent | where {$_.computerName -match 'dc'} | ft name,proxyingEnabled&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Enable the proxy setting for all agents with a particular string in the computer name:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $agents = get-agent | where {$_.computerName -match 'dc'} &lt;BR&gt;&amp;gt; $agents | foreach {$_.ProxyingEnabled = $true}&lt;BR&gt;&amp;gt; $agents | foreach {$_.ApplyChanges()}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;nbsp;&lt;/P&gt;&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;Move all agents on a subnet to a different management server: &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $ms = get-managementServer | where {$_.name -eq 'OpsMgr02.greenGargantua.com'}&lt;BR&gt;&amp;gt; $agents = get-agent | where {$_.IPAddress -match '10.2.*.*'} &lt;BR&gt;&amp;gt; $agents | set-managementServer -primaryManagementServer $ms&lt;/FONT&gt;&lt;BR&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;H1&gt;Security&lt;/H1&gt;
&lt;P align=left&gt;Get list of roles a user belongs to:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-userRole | where {$_.users -match 'iggy'} | ft name&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Add list of users from a text file to a user role:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Script: AddUsersFromFile.ps1&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&lt;/P&gt;param($file) 
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;$entries = import-csv -path $file&lt;BR&gt;foreach ($entry in $entries) {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $role = get-userRole | where {$_.name -eq $entry.role}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; add-userToUserRole -userRole $role -user $entry.user&lt;BR&gt;} 
&lt;P&gt;Sample Text File: users.txt&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;role,user&lt;BR&gt;Marketing,contoso\iggy&lt;BR&gt;Marketing,contoso\johnny&lt;BR&gt;Finance,contoso\sid&lt;BR&gt;IT,contoso\trent&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Running Script: 
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; c:\scripts\AddUsersFromFile -file c:\scripts\users.txt&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;H1&gt;Monitoring Classes and Objects&lt;/H1&gt;
&lt;BLOCKQUOTE&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left&gt;List all monitoring classes:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-monitoringClass&lt;FONT face="Courier New"&gt; | ft name&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;List all SQL 2005 databases:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; (get-monitoringClass&lt;FONT face="Courier New"&gt; -name Microsoft.SQLServer.2005.Database) | get-monitoringObject | ft name&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;OR&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; (get-monitoringClass&lt;FONT face="Courier New"&gt; | where {$_.displayName -eq 'SQL 2005 DB'} | get-monitoringObject | ft name&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;List all Windows computers and their IP addresses:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; get-monitoringClass -name Microsoft.Windows.Computer | get-monitoringObject | foreach {$_."[Microsoft.Windows.Computer].IPAddress"}&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;List all monitoring classes in the SQL Server 2005 Discovery management pack&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $mp = get-managementPack -name Microsoft.SQLServer.2005.Discovery&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $mp | get-monitoringClass | ft name&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Display the proxy settings for all agents holding a particular class:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mc = get-monitoringClass -name 'Microsoft.Windows.Server.AD.DomainControllerRole'&lt;BR&gt;&amp;gt; $&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;mos = $mc | get-monitoringObject &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $mo | foreach {get-agent | where {$_.computerName -eq $mo.name}} | ft name,proxyingEnabled&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Enable the proxy settings for all agents holding a particular class:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mc = get-monitoringClass -name 'Microsoft.Windows.Server.AD.DomainControllerRole'&lt;BR&gt;&amp;gt; $mos = $mc | get-monitoringObject &lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;gt; foreach ($mo in $mos) {&lt;BR&gt;&amp;nbsp;&amp;nbsp; $agent = get-agent | where {$_.computerName -eq $mo.displayName}&lt;BR&gt;&amp;nbsp;&amp;nbsp; $agent.proxyingEnabled = $true&lt;BR&gt;&amp;nbsp;&amp;nbsp; $agent.applyChanges()&lt;BR&gt;}&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;H1&gt;Maintenance Mode&lt;/H1&gt;
&lt;P align=left&gt;Set maintenance mode for a single object:&amp;nbsp; &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $StartTime = (get-Date '4/1/2008 22:00').ToUniversalTime()&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $EndTime = (get-Date '4/2/2008 2:00').ToUniversalTime()&lt;/FONT&gt;&lt;BR&gt;&amp;gt; $mc = get-monitoringClass -name Microsoft.SQLServer.2005.Database &lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mo = get-monitoringObject -monitoringClass $mc | where {$_.name -eq 'MyDatabase'}&lt;BR&gt;&amp;gt; new-maintenanceWindow -monitoringObject $mo -startTime $StartTime -endTime $EndTime -reason PlannedOther -comment "Scheduled maintenance."&lt;/FONT&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&lt;FONT face="Courier New"&gt;&lt;BR&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;/FONT&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Set maintenance mode for an object and all of its contained objects:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $StartTime = (get-Date '4/1/2008 22:00').ToUniversalTime()&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $EndTime = (get-Date '4/2/2008 2:00').ToUniversalTime()&lt;/FONT&gt;&lt;BR&gt;&amp;gt; $mc = get-monitoringClass -name Microsoft.Windows.Computer &lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mo = get-monitoringObject -monitoringClass $mc | where {$_.name -eq 'srv01'}&lt;BR&gt;&amp;gt; $mo.ScheduleMaintenanceMode($StartTime,$EndTime,PlannedOther,"Nightly reboot.","Recursive")&lt;/FONT&gt;&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Schedule maintenance mode for all computers in a group (uses &lt;A href="http://blogs.msdn.com/boris_yanushpolsky/archive/2008/03/04/one-more-maintenance-mode-script.aspx" mce_href="http://blogs.msdn.com/boris_yanushpolsky/archive/2008/03/04/one-more-maintenance-mode-script.aspx"&gt;GroupMM.ps1&lt;/A&gt;):&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;FONT face="Courier New"&gt;&amp;gt; C:\WINDOWS\system32\windowspowershell\v1.0\powershell.exe "c:\scripts\GroupMM.ps1" -groupName:'Nightly Reboots' -hours:2 -rmsServerName:'OpsMgr01' -startMM:$true&lt;/FONT&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;View maintenance mode history for an object:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mc = get-monitoringClass -name Microsoft.Windows.Computer&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mo = get-monitoringObject -monitoringClass $mc | where {$_.name -eq 'srv01'}&lt;BR&gt;&amp;gt; $mo | get-maintenanceWindow -history&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Tasks&lt;/H1&gt;
&lt;P&gt;Run task to enable audit collection on all agents: &lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; $task = get-task | where {$_.name -eq 'Microsoft.SystemCenter.EnableAuditCollectionService'}&lt;BR&gt;&amp;gt; $mc = get-monitoringClass | where {$_.name -eq 'Microsoft.SystemCenter.HealthService'}&lt;BR&gt;&amp;gt; $mc | get-monitoringObject | foreach {start-task -task $task -targetMonitoringObject $_}&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Data&lt;/H1&gt;
&lt;P align=left&gt;View all unresolved alerts:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-alert -criteria "ResolutionState &amp;lt;&amp;gt; 255"&lt;/FONT&gt; &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;View all alerts grouped by severity and name&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-alert -criteria "ResolutionState &amp;lt;&amp;gt; 255" | sort severity,name | group severity,name&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;View alerts from a particular rule group by managed object:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; get-alert -criteria "ResolutionState &amp;lt;&amp;gt; 255" | where {$_.name -match 'Script or Executable Failed to run'} | group monitoringObjectDisplayName&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Change resolution state of alerts from a particular rule group by managed object:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New" size=2&gt;&amp;gt; get-alert -criteria "ResolutionState &amp;lt;&amp;gt; 255" | where {$_.name -match 'Script or Executable Failed to run'} | group monitoringObjectDisplayName | foreach {&lt;BR&gt;&amp;gt;&amp;gt; $_.ResolutionState = 50&lt;BR&gt;&amp;gt;&amp;gt; $_.update("Comment")&lt;BR&gt;&amp;gt;&amp;gt;}&lt;BR&gt;&amp;gt;&amp;gt;&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Resolve all alerts generated by rules as opposed to monitors:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-alert -criteria "ResolutionState &amp;lt;&amp;gt; 255 and IsMonitorAlert = 'False'" | resolve-Alert&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;Reset health for a monitor called "Manual monitor" on all objects of the class "Contoso.MyCustomClass" currently in an Error state.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mon = get-monitor | where {$_.displayName -eq 'Manual monitor'}&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $mc = get-monitoringClass -name Contoso.MyCustomClass&lt;BR&gt;&amp;gt; $mc | get-monitoringObject | where {$_.HealthState -eq 'Error'} | foreach {$_.ResetMonitoringState($mon)}&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Performance Data&lt;/H1&gt;
&lt;P&gt;Extract processor utilization data for all computers for the month of March 2008 to a comma delimited file.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $startTime = get-date '3/1/2008'&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $endTime = get-date '3/31/2008'&lt;BR&gt;&lt;/FONT&gt;&lt;FONT face="Courier New"&gt;&amp;gt; $pc = get-performanceCounter -criteria: "ObjectName='Processor' and CounterName='% Processor Time' and MonitoringObjectPath='web02.bwren.com'"&lt;BR&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-performanceCounterValue -startTime $startTime -endTime $endTime -performanceCounter $pc | export-csv c:\scripts\mom\perf.csv&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;H1&gt;&lt;FONT face="Courier New" size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/H1&gt;
&lt;H1&gt;Management Pack Elements&lt;/H1&gt;
&lt;P align=left&gt;List all rules by management pack:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-rule | select @{name="MP";expression={foreach-Object {$_.GetManagementPack().DisplayName}}},DisplayName | sort mp,displayName &lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;List all monitors in a specific management pack:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; (get-managementPack -name Microsoft.SQLServer.2005.Monitoring) | get-monitor | sort displayName | ft displayName&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;List all disabled discoveries:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P align=left&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-discovery | where {$_.enabled -eq 'false'} | ft displayName&lt;/FONT&gt; &lt;/P&gt;&lt;/BLOCKQUOTE&gt;
&lt;P align=left mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P align=left&gt;View the display name, category, and enabled status of all performance collection rules in the SQL Server 2005 Monitoring management pack:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;FONT face="Courier New"&gt;&amp;gt; get-rule -managementPack $mp | where {$_.category -eq 'PerformanceCollection'} | ft displayName,category,enabled&lt;/FONT&gt;&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2988208" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>Great Minds Think Alike</title><link>http://blogs.technet.com/brianwren/archive/2008/03/04/great-minds-think-alike.aspx</link><pubDate>Wed, 05 Mar 2008 07:46:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2962642</guid><dc:creator>Brian Wren</dc:creator><slash:comments>8</slash:comments><comments>http://blogs.technet.com/brianwren/comments/2962642.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=2962642</wfw:commentRss><description>&lt;p&gt;I just got done with my previous post on setting maintenance mode for a group of objects, and I happened to check &lt;a href="http://blogs.msdn.com/boris_yanushpolsky/"&gt;Boris Yanushpolsky's blog&lt;/a&gt;.&amp;nbsp;&amp;nbsp; Bori's blog is an outstanding reference for various Command Shell scripts, and I have to give him credit for helping me come up to speed on several concepts.&amp;nbsp; Turns out just tonight put up a script for....yep, you guessed it....&lt;a href="http://blogs.msdn.com/boris_yanushpolsky/archive/2008/03/04/one-more-maintenance-mode-script.aspx"&gt;setting maintenance mode on a group of objects&lt;/a&gt;. &lt;/p&gt; &lt;p&gt;As it turns out, I spent more time getting the script to run in a management pack, using overrides, etc.&amp;nbsp; The script that Boris did is more complex than the one I did by putting computers into maintenance mode along with their health service.&amp;nbsp; If that one fits your requirements better, than it should take all that much effort to move it into my sample management pack.&amp;nbsp; Just a matter of pasting the script code into my write action and swapping around some script arguments.&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2962642" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>Scheduling Groups of Objects for Maintenance Mode</title><link>http://blogs.technet.com/brianwren/archive/2008/02/28/scheduling-groups-of-objects-for-maintenance-mode.aspx</link><pubDate>Thu, 28 Feb 2008 18:08:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2940453</guid><dc:creator>Brian Wren</dc:creator><slash:comments>5</slash:comments><comments>http://blogs.technet.com/brianwren/comments/2940453.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=2940453</wfw:commentRss><description>&lt;P&gt;I was given a challenge recently to come up with a solution for an organization that wanted to suppress any alerts for certain computers and services during a particular time window every night.&amp;nbsp; The particular set of objects and the times in question had to be manageable by the administrators - preferably from the Operations Console.&lt;/P&gt;
&lt;P&gt;This is a great example for a few concepts, so this will be a pretty long post where I'll describe each step along the way.&amp;nbsp; If you just want the answer, scroll to the link at the end for the sample MP.&amp;nbsp; Otherwise, you should find some good information on the following concepts:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Launching a PowerShell script from a rule 
&lt;LI&gt;Composing a rule made up of a data source and write action 
&lt;LI&gt;Replacing explicit values in a rule with overrides 
&lt;LI&gt;Creating a simple custom class&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;First of all, the obvious answer to suppressing alerts is to get those objects into maintenance mode.&amp;nbsp; That way we not only aren't bothered by the alerts, but we can also remove this time window from any availability reporting.&amp;nbsp; The questions that we're faced with though are:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;How can we schedule maintenance mode on a regular basis? 
&lt;LI&gt;How can we set maintenance mode for a set of objects? 
&lt;LI&gt;How can we give control to the administrators through the Operations Console?&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;One answer for our challenge might be to write a Command Shell script to put an object in maintenance mode and then launch it from the Windows Scheduler.&amp;nbsp; That would handle question 1, but it would leave us hanging on questions 2 and 3. &lt;/P&gt;
&lt;P&gt;A very straightforward solution would be to create a group in OpsMgr.&amp;nbsp; Instead of setting maintenance mode for a single object, the script could put each member of the group in maintenance mode.&amp;nbsp; Administrators could easily populate the group with any objects that should be included in the maintenance window.&amp;nbsp; Assuming we had a script that could do that group enumeration, question 2 is covered.&amp;nbsp; In order to really address question 3, we would need to launch the script from an OpsMgr management pack instead of the Windows Scheduler and have the ability to overwrite critical parameters.&amp;nbsp; 
&lt;P&gt;So that leaves us with two challenges - setting maintenance mode for a group of objects and creating a rule to launch the script from a management pack.&amp;nbsp; Let's take them one at a time.&amp;nbsp; First the script..... 
&lt;H1&gt;Setting Maintenance Mode on a Group of Objects&lt;/H1&gt;
&lt;P&gt;We're going to need Command Shell in order to enumerate the group and set maintenance mode.&amp;nbsp; I'm assuming that we're going to end up creating a rule calling powershell.exe as described in my &lt;A href="http://blogs.technet.com/brianwren/archive/2008/02/20/running-powershell-scripts-from-a-management-pack.aspx" mce_href="http://blogs.technet.com/brianwren/archive/2008/02/20/running-powershell-scripts-from-a-management-pack.aspx"&gt;previous blog post&lt;/A&gt;, so we're going to need to need the script to include the code to load the Command Shell snap-in and setup the connection to the management server.&amp;nbsp; When we launch Command Shell from the menu, this is done automatically done for us. 
&lt;P&gt;The script should accept the group name as an argument and then enumerate all members of that group.&amp;nbsp; In specific OpsMgr terms, that means that we need to enumerate the objects that are target of a Containment relationship with the group's class.&amp;nbsp; 
&lt;P&gt;If we use the New-MaintenanceWindow CmdLet, then we would need to write a function to recurs through the group members and follow each group members down through its set of hosted and contained objects.&amp;nbsp; Rather than use that CmdLet, I'm going to use the &lt;A href="http://msdn2.microsoft.com/en-us/library/bb424489.aspx" mce_href="http://msdn2.microsoft.com/en-us/library/bb424489.aspx"&gt;ScheduleMaintenanceMode&lt;/A&gt; method on the monitoring object class.&amp;nbsp; That method includes an argument called TraversalDepth.&amp;nbsp; A value of "OneLevel" means that only the object itself will be put into maintenance while a value of "Recursive" means that we will follow hosting and containment relationships all the way down the object tree setting maintenance mode on each object along the way. A middle ground would be nice where we could just address the second level of objects, which in our case would be the specific group members and not their contained objects, but that's a scenario we're going to have to address on our own. 
&lt;P&gt;I thus have two scenarios I want the script to support - setting maintenance mode for just the objects contained in the group and setting maintenance mode for those objects in addition to all of their contained objects.&amp;nbsp; The second scenario is actually easier since we just execute ScheduleMaintenanceMode against the group with TraversalDepth set the "Recursive".&amp;nbsp; For the first method, we're going to have the enumerate the group contents ourselves and then set maintenance mode for each one. 
&lt;P&gt;With all of that said, my script is below.&amp;nbsp; Notice that I'm accepting as arguments the name of the group (not to be confused with the Display Name), the number of hours for maintenance, whether to include hosted objects, and the description.&amp;nbsp; We'll make most of these overrideable on the rule so the administrator has control over them.&lt;PRE class=csharpcode&gt;$groupName = $args[0]
$HoursInMaintenance = $args[1]
$IncludeHostedObjects = $args[2]
$Description = $args[3]
$CommandShellPath = $args[4]

Add-PSSnapin &lt;SPAN class=str&gt;"Microsoft.EnterpriseManagement.OperationsManager.Client"&lt;/SPAN&gt;;
cd &lt;SPAN class=str&gt;"$CommandShellPath"&lt;/SPAN&gt;
.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1

$api = new-object -comObject &lt;SPAN class=str&gt;"MOM.ScriptAPI"&lt;/SPAN&gt;
$api.LogScriptEvent(&lt;SPAN class=str&gt;"SetMaintenanceMode"&lt;/SPAN&gt;,100,4,&lt;SPAN class=str&gt;"Maintenance mode set for all members of group: $groupName"&lt;/SPAN&gt;)

$startTime = (Get-Date).ToUniversalTime()
$endTime = $startTime.AddHours($HoursInMaintenance)

$group = get-monitoringClass -name $groupName | get-monitoringObject

&lt;SPAN class=kwrd&gt;if&lt;/SPAN&gt; ($IncludeHostedObjects &lt;SPAN class=preproc&gt;-eq&lt;/SPAN&gt; $true) 
{
    $group.ScheduleMaintenanceMode($startTime,$endTime,&lt;SPAN class=str&gt;"PlannedOther"&lt;/SPAN&gt;,$Description,&lt;SPAN class=str&gt;"Recursive"&lt;/SPAN&gt;)
}
&lt;SPAN class=kwrd&gt;else&lt;/SPAN&gt;
{
    $classContain = get-relationshipClass -name &lt;SPAN class=str&gt;'System.Containment'&lt;/SPAN&gt;
    $relations = $group | get-relationshipObject | where {$_.SourceMonitoringObject &lt;SPAN class=preproc&gt;-eq&lt;/SPAN&gt; $group} 
    $groupMembers = $relations | &lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; {$_.TargetMonitoringObject}

    &lt;SPAN class=kwrd&gt;foreach&lt;/SPAN&gt; ($object &lt;SPAN class=kwrd&gt;in&lt;/SPAN&gt; $groupMembers)
    {
        $object.ScheduleMaintenanceMode($startTime,$endTime,&lt;SPAN class=str&gt;"PlannedOther"&lt;/SPAN&gt;,$Description,&lt;SPAN class=str&gt;"OneLevel"&lt;/SPAN&gt;)
    }
}&lt;/PRE&gt;&lt;PRE class=csharpcode&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;STYLE type=text/css&gt;.csharpcode {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	MARGIN: 0em; WIDTH: 100%; BACKGROUND-COLOR: #f4f4f4
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	MARGIN: 0em; WIDTH: 100%; BACKGROUND-COLOR: #f4f4f4
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;STYLE type=text/css&gt;.csharpcode {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	FONT-SIZE: small; COLOR: black; FONT-FAMILY: consolas, "Courier New", courier, monospace; BACKGROUND-COLOR: #ffffff
}
.csharpcode PRE {
	MARGIN: 0em
}
.csharpcode .rem {
	COLOR: #008000
}
.csharpcode .kwrd {
	COLOR: #0000ff
}
.csharpcode .str {
	COLOR: #006080
}
.csharpcode .op {
	COLOR: #0000c0
}
.csharpcode .preproc {
	COLOR: #cc6633
}
.csharpcode .asp {
	BACKGROUND-COLOR: #ffff00
}
.csharpcode .html {
	COLOR: #800000
}
.csharpcode .attr {
	COLOR: #ff0000
}
.csharpcode .alt {
	MARGIN: 0em; WIDTH: 100%; BACKGROUND-COLOR: #f4f4f4
}
.csharpcode .lnum {
	COLOR: #606060
}
&lt;/STYLE&gt;

&lt;H1&gt;Creating the Rule&lt;/H1&gt;
&lt;P&gt;The next question is how we're going to launch that script and give administrators control over the schedule.&amp;nbsp; We could do that from the Windows Scheduler, but it would be more straightforward for the administrator if we put it into an OpsMgr rule.&amp;nbsp; If we configure it correctly, we can allow our administrators to use overrides to control the schedule, length of maintenance mode, and whether to include contained objects.&amp;nbsp; &lt;/P&gt;
&lt;H2&gt;Data Source&lt;/H2&gt;
&lt;P&gt;The rule will need a data source and a write action.&amp;nbsp; Since we want to execute the script on a nightly schedule, System.Scheduler will be a perfect data source.&amp;nbsp; There is one little trick with that data source though.&amp;nbsp; It allows you to define multiple schedules that have a start and a stop time.&amp;nbsp; In the context we are going to use it though, the stop time is ignored.&amp;nbsp; It will have to be larger than the start time to prevent errors, but other than that it won't be used.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;You could just use System.Scheduler unchanged in which case you'll get the benefit of the dialog box for setting multiple schedules.&amp;nbsp; In that case, you would need to modify the rule itself to change the schedule though.&amp;nbsp; Since I want to control it through overrides I'm going to limit us to a single schedule, and I'm going to have to set the parameters myself.&amp;nbsp; The Start and End times are pretty obvious.&amp;nbsp; The DaysOfWeekMask is a little confusing.&amp;nbsp; This is the integer value of a bit mask with each day representing a single bit.&amp;nbsp; If you're familiar with bit masks you won't have a problem. If not, just determine the appropriate value by using the following values for each day of the week: Su-1, M-2, T-4, W-8, Th-16, F-32, Sa-64.&amp;nbsp; Just add up the values for the days you want the script to run.&amp;nbsp; If you want all days of the week, they'll add up to 127.&amp;nbsp; If you just want Sunday, the value is 1.&amp;nbsp; Just Tuesday and Thursday would be 20.&lt;/P&gt;
&lt;P&gt;With all of that said, here's a valid data source for running the script every day of the week at 10:00 pm.&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DataSources&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DataSource ID="Scheduler" TypeID="System!System.Scheduler"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Scheduler&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;WeeklySchedule&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Windows&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Daily&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Start&amp;gt;22:00$&amp;lt;/Start&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;End&amp;gt;23:59&amp;lt;/End&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DaysOfWeekMask&amp;gt;127&amp;lt;/DaysOfWeekMask&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Daily&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Windows&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/WeeklySchedule&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ExcludeDates/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Scheduler&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/DataSource&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/DataSources&amp;gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;To define overrides though, we have to create a new module type.&amp;nbsp; Rather than using this data source directly in the rule, I'll create a data source allowing the StartTime and DaysOfWeekMask to be overriden.&amp;nbsp; The rule will then use the new data source module.&amp;nbsp; Notice in the data source below that I've changed the changed the values for &amp;lt;Start&amp;gt; and &amp;lt;DaysOfTheWeeMask&amp;gt; to overrideable values that will be provided by the rule itself.&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&amp;lt;DataSourceModuleType ID="bwren.Maintenance.DataSource.Scheduler" Accessibility="Public"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Configuration&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="StartTime" type="xsd:string" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="DaysOfWeekMask" type="xsd:integer" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Configuration&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameters&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameter ID="StartTime" ParameterType="string" Selector="$Config/StartTime$"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameter ID="DaysOfWeekMask" ParameterType="int" Selector="$Config/DaysOfWeekMask$"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OverrideableParameters&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ModuleImplementation&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Composite&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MemberModules&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DataSource ID="DS" TypeID="System!System.Scheduler"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Scheduler&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;WeeklySchedule&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Windows&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Daily&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Start&amp;gt;$Config/StartTime$&amp;lt;/Start&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;End&amp;gt;23:59&amp;lt;/End&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;DaysOfWeekMask&amp;gt;$Config/DaysOfWeekMask$&amp;lt;/DaysOfWeekMask&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Daily&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Windows&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/WeeklySchedule&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ExcludeDates/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Scheduler&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/DataSource&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/MemberModules&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Composition&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Node ID="DS"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Composition&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Composite&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/ModuleImplementation&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OutputType&amp;gt;System!System.TriggerData&amp;lt;/OutputType&amp;gt;&lt;BR&gt;&amp;lt;/DataSourceModuleType&amp;gt;&lt;/FONT&gt; 
&lt;H2&gt;Write Action&lt;/H2&gt;
&lt;P&gt;The write action is just a matter of launching our PowerShell script.&amp;nbsp; We'll again need a new module type to handle overrides.&amp;nbsp; That strategy has other benefits anyway, since we can put the complexity in the module type and keep the rule simple.&amp;nbsp; That will make it easy to create other rules for other groups.&lt;/P&gt;
&lt;P&gt;The module type using our script is shown below.&amp;nbsp; I won't bother explaining all the details since you can get that from the &lt;A href="http://blogs.technet.com/brianwren/archive/2008/02/20/running-powershell-scripts-from-a-management-pack.aspx" mce_href="http://blogs.technet.com/brianwren/archive/2008/02/20/running-powershell-scripts-from-a-management-pack.aspx"&gt;PowerShell post&lt;/A&gt;.&amp;nbsp; The formatting gets pretty screwed up here, so you might just want to have a look at it in the &lt;A href="http://brianwren.members.winisp.net/Management%20Packs/bwren.MaintenanceMode.xml" mce_href="http://brianwren.members.winisp.net/Management%20Packs/bwren.MaintenanceMode.xml"&gt;sample MP&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;WriteActionModuleType ID="bwren.Maintenance.WriteAction.SetMaintenance" Accessibility="Public"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Configuration&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="GroupName" type="xsd:string" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="HoursInMaintenance" type="xsd:integer" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="IncludeHostedObjects" type="xsd:string" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsd:element name="Description" type="xsd:string" xmlns:xsd="&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;http://www.w3.org/2001/XMLSchema"/&lt;/FONT&gt;&lt;FONT face=Consolas size=2&gt;&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Configuration&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameters&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameter ID="HoursInMaintenance" Selector="$Config/HoursInMaintenance$" ParameterType="int"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OverrideableParameter ID="IncludeHostedObjects" Selector="$Config/IncludeHostedObjects$" ParameterType="string"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/OverrideableParameters&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ModuleImplementation Isolation="Any"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Composite&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;MemberModules&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;WriteAction ID="WA1" TypeID="System!System.CommandExecuter"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ApplicationName&amp;gt;%windir%\system32\windowspowershell\v1.0\powershell.exe&amp;lt;/ApplicationName&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;WorkingDirectory/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;CommandLine&amp;gt;-Command "&amp;amp;amp; {.\SetMaintenance.ps1 $Config/GroupName$ $Config/HoursInMaintenance$ $Config/IncludeHostedObjects$ '$Config/Description$'}"&amp;lt;/CommandLine&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;SecureInput/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TimeoutSeconds&amp;gt;30&amp;lt;/TimeoutSeconds&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;RequireOutput&amp;gt;true&amp;lt;/RequireOutput&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Files&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;File&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Name&amp;gt;SetMaintenance.ps1&amp;lt;/Name&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Contents&amp;gt;&amp;lt;![CDATA[&lt;BR&gt;$groupName = $args[0]&lt;BR&gt;$HoursInMaintenance = $args[1]&lt;BR&gt;$IncludeHostedObjects = $args[2]&lt;BR&gt;$Description = $args[3] &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client";&lt;BR&gt;cd C:\"Program Files"\"System Center Operations Manager 2007"&lt;BR&gt;.\Microsoft.EnterpriseManagement.OperationsManager.ClientShell.Startup.ps1 &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;$startTime = (Get-Date).ToUniversalTime()&lt;BR&gt;$endTime = $startTime.AddHours($HoursInMaintenance) &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;$group = get-monitoringClass -name $groupName | get-monitoringObject &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;if ($IncludeHostedObjects -eq $true) &lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $group.ScheduleMaintenanceMode($startTime,$endTime,"PlannedOther",$Description,"Recursive")&lt;BR&gt;}&lt;BR&gt;else&lt;BR&gt;{&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $classContain = get-relationshipClass -name 'System.Containment'&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $relations = $group | get-relationshipObject | where {$_.SourceMonitoringObject -eq $group} &lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; $groupMembers = $relations | foreach {$_.TargetMonitoringObject} &lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach ($object in $groupMembers)&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $object.ScheduleMaintenanceMode($startTime,$endTime,"PlannedOther",$Description,"OneLevel")&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;BR&gt;}&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ]]&amp;gt;&amp;lt;/Contents&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Unicode&amp;gt;true&amp;lt;/Unicode&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/File&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Files&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/WriteAction&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/MemberModules&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Composition&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Node ID="WA1"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Composition&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Composite&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/ModuleImplementation&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;OutputType&amp;gt;System!System.CommandOutput&amp;lt;/OutputType&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;InputType&amp;gt;System!System.BaseData&amp;lt;/InputType&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/WriteActionModuleType&amp;gt;&lt;/FONT&gt; 
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&lt;/FONT&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;Setting the Rule Target&lt;/H1&gt;
&lt;P&gt;With those modules created, we need a rule that includes each data source and specifies the required arguments.&amp;nbsp; The biggest question is what to use as its target.&amp;nbsp; Technically, we can target anything that will end up deploying to an agent with PowerShell and Command Shell installed.&amp;nbsp; We only want a single agent to get it though.&amp;nbsp; We also want to make sure that our target is going to be accessible to the server admins.&amp;nbsp; The root management server typically has Command Shell installed, and this is a perfect candidate for this task.&amp;nbsp; Chances are pretty good though that we don't want to give permission to our administrators to author rules against our RMS.&lt;/P&gt;
&lt;P&gt;I had thought of targeting the group itself since, as described in another &lt;A href="http://blogs.technet.com/brianwren/archive/2007/08/22/targeting-rules-and-monitors.aspx" mce_href="http://blogs.technet.com/brianwren/archive/2007/08/22/targeting-rules-and-monitors.aspx"&gt;previous post&lt;/A&gt; the root management server "hosts" groups, so that's where the rule would get deployed.&amp;nbsp; I had some issues with this working reliably though, and I also thought it might get a bit confusing.&lt;/P&gt;
&lt;P&gt;The solution I went with was to create a new class based on ComputerRole called CommandShellProxy. This can serve as the target for any rules I want to create that launch a Command Shell script.&amp;nbsp; I can give permission to different people to override rules targeted at it without giving them access to the rules and monitors directly targeting the RMS.&amp;nbsp; As an added benefit, I stored the path to the PowerShell executable and the Command Shell snap-in so I don't have to hardcode those into the rule.&lt;/P&gt;
&lt;P&gt;&lt;FONT face=Consolas size=2&gt;&amp;lt;ClassType ID="bwren.MaintenanceMode.CommandShellProxy" Accessibility="Public" Abstract="false" Base="Windows!Microsoft.Windows.ComputerRole" Hosted="true" Singleton="false"&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Property ID="PowerShellPath" Type="string"/&amp;gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Property ID="CommandShellPath" Type="string"/&amp;gt;&lt;BR&gt;&amp;lt;/ClassType&amp;gt;&lt;/FONT&gt; 
&lt;P&gt;I did a simple registry discovery for my new class and targeted it at the Root Management Server class.&amp;nbsp; The only criteria I'm using is determining whether Command Shell is installed.&amp;nbsp; If you want to use something other than the RMS as your Command Shell proxy, all you would have to do is change that discovery.&lt;/P&gt;
&lt;P&gt;I didn't bother pasting in the discovery XML since I've already cluttered up this post with enough code.&amp;nbsp; You can have a look at it in the sample MP though. &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;H1&gt;End Result&lt;/H1&gt;
&lt;P&gt;Go to the bottom of this post for a link to the sample MP.&amp;nbsp; You can go through the following steps to get it up and running:&lt;/P&gt;
&lt;P&gt;1.&amp;nbsp; Load the management pack &lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_12.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_12.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=139 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb.png" width=475 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=center mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2.&amp;nbsp; Add an object or two to the group &lt;EM&gt;Maintenance Mode Group 1&lt;/EM&gt;. &lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image9.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image9.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=432 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image9_thumb.png" width=451 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image9_thumb.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3.&amp;nbsp; Make sure that you are discovering the Command Shell Proxy by selecting Discovered Inventory.&amp;nbsp; Then click on Change Target and select Command Shell Proxy from the list.&lt;/P&gt;
&lt;P align=center&gt;&amp;nbsp;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_14.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_14.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=139 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_5.png" width=814 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_5.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; Go to the Authoring tab and look at rules for the target &lt;EM&gt;Command Shell Proxy&lt;/EM&gt;. &lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_16.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_16.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=124 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_6.png" width=617 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_6.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P align=center mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;4.&amp;nbsp; Create an override on the rule &lt;EM&gt;Set maintenance mode - group 1&lt;/EM&gt;, and set appropriate values for StartTime, HoursInMaintenance, IncludeHostedObjects, and Description.&amp;nbsp; The allowable values for IncludeHostedObjects are $true and $false (those are the PowerShell variables for True and False.&amp;nbsp; You could do a little script work to allow a boolean in the override and then convert appropriately if you really want).&lt;/P&gt;
&lt;P align=center&gt;&lt;A href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_18.png" mce_href="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_18.png"&gt;&lt;IMG style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" height=239 alt=image src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_7.png" width=604 border=0 mce_src="http://blogs.technet.com/blogfiles/brianwren/WindowsLiveWriter/SchedulingGroupsofObjectsforMaintenanceM_702C/image_thumb_7.png"&gt;&lt;/A&gt; &lt;/P&gt;
&lt;P mce_keep="true"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I know this is a long and detailed post, but it seemed like a good opportunity to illustrate a few points.&amp;nbsp; Hope it's helpful.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2940453" width="1" height="1"&gt;</description><enclosure url="http://blogs.technet.com/brianwren/attachment/2940453.ashx" length="27122" type="application/octet-stream" /><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Management+Packs/default.aspx">Management Packs</category></item><item><title>Command Shell Presentation at MMS 2008</title><link>http://blogs.technet.com/brianwren/archive/2008/02/24/command-shell-presentation-at-mms-2008.aspx</link><pubDate>Mon, 25 Feb 2008 08:24:00 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:2930008</guid><dc:creator>Brian Wren</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.technet.com/brianwren/comments/2930008.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=2930008</wfw:commentRss><description>&lt;DIV class=wlWriterSmartContent id=scid:0767317B-992E-4b12-91E0-4F059A8CECA8:9e1d2dbf-be77-4ad8-b2f6-e102e53f84f3 style="PADDING-RIGHT: 0px; DISPLAY: inline; PADDING-LEFT: 0px; FLOAT: none; PADDING-BOTTOM: 0px; MARGIN: 0px; PADDING-TOP: 0px"&gt;&lt;A href="http://technorati.com/tags/" rel=tag mce_href="http://technorati.com/tags/"&gt;&lt;/A&gt;&amp;nbsp;&lt;/DIV&gt;
&lt;P&gt;I will be doing a presentation at the upcoming &lt;A href="http://www.mms-2008.com/" mce_href="http://www.mms-2008.com"&gt;MMS 2008&lt;/A&gt; titled Administrative Scenarios using the Operations Manager 2007 Command Shell.&amp;nbsp; This is a bit of a departure for me since I've presented several times at MMS but usually on management packs and custom monitoring scenarios.&amp;nbsp; This will be a chance to present different solutions I've created with Command Shell working with various customers.&amp;nbsp; Not management packs but still automation, so we're well within my comfort zone.&lt;/P&gt;
&lt;P&gt;I'm working out the different scenarios I'm going to cover right now and already have a list longer than time is going to allow.&amp;nbsp; That list currently includes the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Importing and exporting management packs from a command line 
&lt;LI&gt;Analyzing management pack contents 
&lt;LI&gt;Deploying agents from a command line 
&lt;LI&gt;Modifying settings across multiple agents with a single command 
&lt;LI&gt;Scheduling maintenance mode for single object and related objects 
&lt;LI&gt;Resolving alerts matching specified criteria 
&lt;LI&gt;Launching tasks from a command line 
&lt;LI&gt;Extracting performance and alert data&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Depending on the scenario, the solution may be a CmdLet or two or may require a full blown script.&amp;nbsp; I personally hate trying to feverishly copy code and specific command lines while sitting in a presentation, so I'll include the code for each scenario here on the blog just prior to the presentation itself.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;If you're going to be attending MMS this year and have any scenarios you'd like to see covered in my presentation, let me know.&amp;nbsp; Obviously I can't guarantee anything, but I would like to see if there are any interesting scenarios I haven't thought of.&amp;nbsp; I could also use a little feedback on the scenarios that are most interesting since a couple are probably going to have to fall off of that list due to time constraints.&lt;/P&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=2930008" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category></item><item><title>Exporting Management Packs</title><link>http://blogs.technet.com/brianwren/archive/2007/08/22/exporting-management-packs.aspx</link><pubDate>Wed, 22 Aug 2007 19:33:35 GMT</pubDate><guid isPermaLink="false">d5e57398-b9ef-4490-9955-07cbb4e4a80d:1803505</guid><dc:creator>Brian Wren</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.technet.com/brianwren/comments/1803505.aspx</comments><wfw:commentRss>http://blogs.technet.com/brianwren/commentrss.aspx?PostID=1803505</wfw:commentRss><description>&lt;p&gt;Obviously, /a great way to learn how to author a management pack is to look at existing ones.&amp;nbsp; The problem is that most of the interesting ones are sealed so you can't read the file, and the Operations Console won't allow you to export a sealed management pack.&amp;nbsp; &lt;/p&gt; &lt;p&gt;This is actually very easy using Command Shell.&amp;nbsp; You can export a single management pack or export the entire set of installed management packs from a management group.&amp;nbsp; This is my personal favorite as I like to have the entire set of management packs available for my reference.&lt;/p&gt; &lt;p&gt;Command Shell is an optional component of the Operations Manager User Interfaces, so it's probably something you already have installed.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Exporting a single management pack&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;To export a single management pack, use the following command:&lt;/p&gt; &lt;p align="center"&gt;get-managementPack -name &amp;lt;Name of MP&amp;gt; | export-managementPack -path &amp;lt;Directory to store exported file&amp;gt;&lt;/p&gt; &lt;p&gt;For example, to export the SQL Library MP to a directory called c:\mp:&lt;/p&gt; &lt;p align="center"&gt;get-managementPack -name Microsoft.SQLServer.Library | export-managementPack -path c:\mp&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Exporting all management packs&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;It's actually easier to export all management packs since you don't have to specify the -name parameter on the get-managementPack CmdLet.&amp;nbsp; Just use the following, and you will fill c:\mp with the entire set of management packs installed in your management group.&lt;/p&gt; &lt;p align="center"&gt;get-managementPack | export-managementPack -path c:\mp&lt;/p&gt; &lt;p align="left"&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;Update on 2/17/2008&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;I would be completely remiss if I didn't update this post to refer to Boris' PowerShell script that can convert an MP file to XML from a command line.&amp;nbsp; Certainly easier if you need to convert a sealed management pack that you don't already have imported into a management group.&amp;nbsp; &lt;/p&gt; &lt;p&gt;&lt;a title="http://blogs.msdn.com/boris_yanushpolsky/archive/2007/08/16/unsealing-a-management-pack.aspx" href="http://blogs.msdn.com/boris_yanushpolsky/archive/2007/08/16/unsealing-a-management-pack.aspx"&gt;http://blogs.msdn.com/boris_yanushpolsky/archive/2007/08/16/unsealing-a-management-pack.aspx&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.technet.com/aggbug.aspx?PostID=1803505" width="1" height="1"&gt;</description><category domain="http://blogs.technet.com/brianwren/archive/tags/OpsMgr/default.aspx">OpsMgr</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Command+Shell/default.aspx">Command Shell</category><category domain="http://blogs.technet.com/brianwren/archive/tags/Management+Packs/default.aspx">Management Packs</category></item></channel></rss>