Scheduling Maintenance for an Object in Ops Mgr 2007
Since we have posted the Powershell script to put OpsMgr 2007 computers into maintenance, users have asked us how to put a service or application into maintenance, allowing other monitoring activities on a server to continue. We have figured out how to implement maintenance at this more granular level and have outlined the steps below using IIS as an example. The key to this working is that whatever application/service you want to put into maintenance, must be configured as an object in OpsMgr 2007.
*NOTE* In this example, Step 1 is looking for the NetBios name of the server. Please replace “PUT_SERVER_NAME_HERE” with the server of your choice.
Step: 1
$agent = get-agent | where {$_.ComputerName -eq “PUT_SERVER_NAME_HERE”}Step: 2
$object = $agent.HostComputer.GetRelatedMonitoringObjects() | where {$_.DisplayName -eq “Microsoft.Windows.InternetInformationServices.2003.ServerRole”}Step: 3
$time = dateStep: 4
$object | New-MaintenanceWindow -startTime $time -endTime: $time.AddMinutes(5) -reason: “UnPlannedOther” -comment: “I luv IIS!”
If you want a longer maintenance window, just increase the number in the parameter $time.AddMinutes(5). For example, to set a 10 minute window, just make the parameter to look like this $time.AddMinutes(10).
We will come out with a script in the near future that will put well-known MS applications into maintenance (assuming the MP is properly designed).


February 6th, 2008 at 8:41 pm
I’m trying to put a web application (Not Agent monitored IIS, this is a linux box without agent monitoring, using the Web Application monitor) into Maint mode, but can’t figure out which object to use.
Presumably I have to use get-agent | where {$_.DisplayName -eq AppName} or something similar. Can anyone help me with how to find the correct object.
Thanks,
February 7th, 2008 at 12:27 am
Okay, I managed to figure this out myself in the end, and this syntax seems to work…
$Now = get-date
$WebAppObject = get-monitoringobject | where {$_.DisplayName –eq “Web Application Name”}
new-maintenancewindow -starttime $Now -endtime $Now.addminutes(60) –comment “Nightly shutdown” –monitoringobject $WebAppObject
February 7th, 2008 at 1:19 am
[…] sample for putting a specific object (regardless of object class) awhile back (check it out HERE). Here’s a good example of how to put an website monitor into maintenance targeting the […]
February 12th, 2008 at 3:41 pm
Can the above be configured on the scom server or a jobs server so that each time a server performs a scheduled reboot it can automatically place itself in maintenance mode? We have a scheduling server and ideally I’d like for each server to place itself in maintenance mode just prior to being rebooted.
April 8th, 2008 at 2:48 am
[…] the code snippet for maintenance mode for any object class HERE or […]