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'
}
}
else
{
 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

  • Anonymous
    October 22, 2007
    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.CheersDennis Cox
  • Anonymous
    October 23, 2007
    what do you mean by the "SMS portion"?
  • Anonymous
    October 24, 2007
    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...
  • Anonymous
    October 24, 2007
    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 = $nullforeach($object in $relatedObjects){$classIds = [Array]$object.SourceMonitoringObject.MonitoringClassIdsforeach($classId in $classIds){if($classId.ToString() -eq $computerClass.Id.ToString()){$hostingComputerInstance = $object.SourceMonitoringObjectbreak;}}}$hostingComputerInstance}$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 $dbInstanceif($computerObject.DisplayName -eq 'dbsrv1.contoso.com'){New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -reason:'PlannedHardwareMaintenance' -monitoringobject:$dbInstance -comment:'comment goes here'}}}else{$computerObject = GetHostingComputerObject $dbInstancesif($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.
  • Anonymous
    February 06, 2008
    The comment has been removed
  • Anonymous
    February 06, 2008
    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
  • Anonymous
    February 29, 2008
    There are many articles that talk about maintenance mode in System Center Operations Manager 2007. Topics
  • Anonymous
    April 14, 2008
    What if I want to put multiple databases with diffferent names but resides on the same server on the maintenance mode? Please help.
  • Anonymous
    April 14, 2008
    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.
  • Anonymous
    July 12, 2008
    Check out Boris Yanushpolsky's blog ( http://blogs.msdn.com/boris_yanushpolsky ). Boris is an SCOM
  • Anonymous
    November 25, 2008
    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.
  • Anonymous
    November 25, 2008
    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.
  • Anonymous
    January 15, 2009
    How do you use the script website monitor script.  I'm new to power shell and I have the same issue.
  • Anonymous
    January 15, 2009
    I am not sure I understand the question. Can you please elaborate?
  • Anonymous
    March 06, 2009
    The comment has been removed