What if I dont want to put the whole computer into maintenance mode?

Sometimes you may not wish to put the whole computer into maintenance mode. Instead you may wish to put just a number of databases or websites into maintenance mode.

The steps are very simple:

1 - Get the monitoring class that represents the type of monitoring objects that you wish to put into maintenance mode

2 - Get the actual monitoring objects

3 - Iterate through the array of monitoring objects and put them into maintenance mode (dont forget to check whether you got a single monitoring object or an array, this is pretty important) 

Here is a sample of how to do this using PowerShell:

$sql2005DBClass = get-monitoringclass | where {$_.DisplayName -eq 'SQL 2005 DB'}

$dbInstances = get-monitoringobject -monitoringclass:$sql2005DBClass | where {$_.Name -match 'TestDB'}

$startTime = [DateTime]::Now

$endTime = $startTime.AddHours(2)

if($dbInstances -is [Array])
foreach($dbInstance in $dbInstances)
 New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedHardwareMaintenance' -monitoringobject:$dbInstance -comment:'comment goes here'
 New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedHardwareMaintenance' -monitoringobject:$dbInstances -comment:'comment goes here'

This script will find all databases where the DB name is like TestDB and then put then into maintenance mode for two hours.

Comments (15)
  1. Dennis Cox says:

    Wonderful stuff. But here is where I am stuck. I want to put the SMS portion into maint. mode.

    I understand the dbinstances, but totally clueless about SMS. I have already determined that it would be an array.


    Dennis Cox

  2. borisyan says:

    what do you mean by the "SMS portion"?

  3. Laurent DE BERTI says:

    Very good,

    If you have 2 instances of TestDB, and of course you just want to put only 1 in maintenance mode, how is it possible ? How to add the computer information in that case to make the difference ?

    Thanks for your very useful blog…

  4. borisyan says:

    Here is how you can do this:

    function GetHostingComputerObject ($monitoringObject)


    $hostingRel = Get-RelationshipClass -name:’System.Hosting’

    $computerClass = Get-MonitoringClass -name:"Microsoft.Windows.Computer"

    $relatedObjects = $monitoringObject.GetMonitoringRelationshipObjectsWhereTarget($hostingRel,[Microsoft.EnterpriseManagement.Configuration.DerivedClassTraversalDepth]::Recursive,[Microsoft.EnterpriseManagement.Common.TraversalDepth]::Recursive) | Select-Object SourceMonitoringObject

    $hostingComputerInstance = $null

    foreach($object in $relatedObjects)


    $classIds = [Array]$object.SourceMonitoringObject.MonitoringClassIds

    foreach($classId in $classIds)


    if($classId.ToString() -eq $computerClass.Id.ToString())


    $hostingComputerInstance = $object.SourceMonitoringObject







    $sql2005DBClass = get-monitoringclass | where {$_.DisplayName -eq ‘SQL 2005 DB’}

    $dbInstances = get-monitoringobject -monitoringclass:$sql2005DBClass | where {$_.Name -match ‘TestDB’}

    $startTime = [DateTime]::Now

    $endTime = $startTime.AddHours(2)

    if($dbInstances -is [Array])


    foreach($dbInstance in $dbInstances)


    $computerObject = GetHostingComputerObject $dbInstance

    if($computerObject.DisplayName -eq ‘dbsrv1.contoso.com’)


    New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:’PlannedHardwareMaintenance’ -monitoringobject:$dbInstance -comment:’comment goes here’






    $computerObject = GetHostingComputerObject $dbInstances

    if($computerObject.DisplayName -eq ‘dbsrv1.Contoso.com’)


    New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:’PlannedHardwareMaintenance’ -monitoringobject:$dbInstances -comment:’comment goes here’



    Basically I added a function that returns the computer which hosts the DB. Then you can check the computer name and decide if you want to put the DB into maintenance mode or not.

  5. Graham Pohl says:

    I’m trying to put a Web Application into maintenance mode, and having trouble trying to figure out which monitoring Object to use, since it’s not a subcomponent of a computer. (Web Server is a linux box, not agent monitored by Ops Mgr).

    What is the correct monitoring Object to use to put a Web Application into Maint mode.


  6. Graham Pohl says:

    I have a syntax for finding the Web Application object which seems to work now, in case anyone else had the same issue:

    $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

  7. SCOM/MOM says:

    There are many articles that talk about maintenance mode in System Center Operations Manager 2007. Topics

  8. Santosh Nepal says:

    What if I want to put multiple databases with diffferent names but resides on the same server on the maintenance mode? Please help.

  9. OpsMgr says:

    I am really happy with this script but not sure how to use it. I am new to the script world. Please explain in details on how to run this script. I would like to schedule this script.

  10. Check out Boris Yanushpolsky's blog ( http://blogs.msdn.com/boris_yanushpolsky ). Boris is an SCOM

  11. Andrew Schilling says:

    Is it possible to put specific monitors that make up an object into maintenance mode?  The situation I have is that we are monitoring several WSS 3.0 servers. On 2 of them, the Timer service is disabled due to a bug.  The SharePoint administrators don’t want to monitor the timer service on these servers for the next 2 weeks while they are troubleshooting and testing to resolve the problem.

  12. borisyan says:

    Unfortunately you cannot put a single monitor into maintenance mode. What you can do for the next two weeks is disable the monitor using an override.

  13. How do you use the script website monitor script.  I’m new to power shell and I have the same issue.

  14. borisyan says:

    I am not sure I understand the question. Can you please elaborate?

  15. Desi says:

    Hello I am getting an error when I run the Web Monitoring on the command shell.

    I Run

    $Now = get-date

    $WebAppObject = get-monitoringobject | where {$_.DisplayName -eq "Test site"}

    New-MaintenanceWindow -starttime $Now -endtime $Now.addminutes(10) -comment "Nightly shutdown" -MonitoringObject $WebAppObject

    and when I type in the third line with that is starting with New-Mainten…. I get this below error –

    New-MaintenanceWindow -starttime $Now -endtime $Now.addminutes(10) -comment ‘Nigh

    tly shutdown’ -MonitoringObject $WebAppObject

    New-MaintenanceWindow : Cannot bind argument to parameter ‘MonitoringObject’ beca

    use it is null.

    At line:1 char:113

    • New-MaintenanceWindow -starttime $Now -endtime $Now.addminutes(10) -comment ‘Ni

    ghtly shutdown’ -MonitoringObject  <<<< $WebAppObject

Comments are closed.

Skip to main content