Welcome to MSDN Blogs Sign in | Join | Help

One more maintenance mode script

Attached is a script that takes a group and puts all the computers in the group (as well as the health service and the healthservice watcher) into maintenance mode.

Here is how you can run the script from the command line to start or stop maintenance mode (without launching powershell.exe)

One of the uses of this script is when you deploy hotfixes to a large number of servers. You can also very easily use Task Scheduler to run this script on a regular basis for your maintenance windows.

Starting MM - powershell "c:\GroupMM.ps1" -groupName:'All Computers' -hours:10 -rmsServerName:'localhost' -startMM:$true

 

Ending MM - powershell "c:\GroupMM.ps1" -groupName:'All Computers' -hours:10 -rmsServerName:'localhost' -startMM:$false

Published Tuesday, March 04, 2008 8:46 PM by Boris Yanushpolsky
Filed under:

Attachment(s): GroupMM.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Ace DDL » OpsMgr2007: Scheduling Groups of Objects for Maintenance Mode

# Maintenance mode targeting

Tuesday, March 25, 2008 11:31 AM by geist_23

Boris,

I have used the maintenance mode scripts that target a group and that works great.  I have created a scheduled task and scheduled it to run against the ‘Maintenance Mode All Computers” Group which is really based on a dynamic formula that simply states: “Object is Microsoft Windows Computer” = True.

All 500 servers go into maintenance mode.

Then one day someone told me that they need their particular server in maintenance mode at a different time! Why would anyone want to have their servers go into maintenance mode at a different time?  

So the dilemma: How to make this all dynamic and not manually explicit.

Group creation can explicitly exclude individual objects.

Group creation cannot reference membership of one group and dynamically exclude it. This is quite a problem.

So then I though there must be a way create to a class with an expression that weeds out unwanted servers that need to be in a different maintenance schedule.

One thing is true. All servers that need to be in alternate maintenance schedules will enjoy the benefit of having their own hosted class.

Therefore, I have a created a hosted (registry type) class that identifies the servers that need to have a different maintenance window:

<Configuration>

 <ComputerName>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/NetworkName$</ComputerName>

 <RegistryAttributeDefinitions>

   <RegistryAttributeDefinition>

     <AttributeName>UTSCheck</AttributeName>

     <Path>SYSTEM\CurrentControlSet\Control\Session Manager\Environment\DFC_Service\UTS</Path>

     <PathType>0</PathType>

     <AttributeType>0</AttributeType>

   </RegistryAttributeDefinition>

 </RegistryAttributeDefinitions>

 <Frequency>600</Frequency>

 <ClassId>$MPElement[Name="DFC.APP.UnifiedTicketingSystem.Base"]$</ClassId>

 <InstanceSettings>

   <Settings>

     <Setting>

       <Name>$MPElement[Name="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Name>

       <Value>$Target/Property[Type="Windows!Microsoft.Windows.Computer"]/PrincipalName$</Value>

     </Setting>

   </Settings>

 </InstanceSettings>

 <Expression>

   <SimpleExpression>

     <ValueExpression>

       <XPathQuery Type="String">Values/UTSCheck</XPathQuery>

     </ValueExpression>

     <Operator>Equal</Operator>

     <ValueExpression>

       <Value Type="String">True</Value>

     </ValueExpression>

   </SimpleExpression>

 </Expression>

</Configuration>

Now how do I create a class that contains all my servers minus the UTS servers?

# re: One more maintenance mode script

Thursday, March 27, 2008 12:11 PM by Nick M

Excellent script Boris - just a quick question, does the group need to be based on the Windows Server object, or can it be any subset? For example, a dynamic list based on Logical disks?

# re: One more maintenance mode script

Friday, March 28, 2008 8:47 PM by Boris Yanushpolsky

I dont think you can exclude a group from another group's definition. What you can do is create another class and create a discovery for this class (instances of this class would be the onces that need to go in MM at the same time). Then include only this class in the group.

# re: One more maintenance mode script

Monday, March 31, 2008 10:14 AM by geist_23

"Then include only this class in the group."

Ultimately, this would fail me as inevitably server instances will be a part of more than one class that I define for maintenanec mode.

# A Great place for SCOM scripts

Sunday, July 13, 2008 7:08 AM by Dario IT Solutions Blog

Check out Boris Yanushpolsky&#39;s blog ( http://blogs.msdn.com/boris_yanushpolsky ). Boris is an SCOM

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker