Welcome to MSDN Blogs Sign in | Join | Help

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.

Published Friday, October 19, 2007 6:27 PM by Boris Yanushpolsky
Filed under:

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

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

Tuesday, October 23, 2007 5:01 AM by Dennis Cox

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.

Cheers

Dennis Cox

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

Tuesday, October 23, 2007 12:23 PM by Boris Yanushpolsky

what do you mean by the "SMS portion"?

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

Thursday, October 25, 2007 12:50 AM by Laurent DE BERTI

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...

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

Thursday, October 25, 2007 3:24 AM by Boris Yanushpolsky

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

break;

}

}

}

$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 $dbInstance

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

{

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

}

}

}

else

{

$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.

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

Wednesday, February 06, 2008 3:35 PM by Graham Pohl

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.

Thanks

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

Wednesday, February 06, 2008 7:29 PM by Graham Pohl

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

# Things to know about Maintenance Mode in System Center Operations Manager 2007

Friday, February 29, 2008 9:45 PM by SCOM/MOM

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

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

Monday, April 14, 2008 11:49 AM by Santosh Nepal

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

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

Monday, April 14, 2008 12:32 PM by OpsMgr

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.

# A Great place for SCOM scripts

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

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

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

Tuesday, November 25, 2008 3:12 PM by Andrew Schilling

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.

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

Tuesday, November 25, 2008 3:41 PM by Boris Yanushpolsky

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.

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

Thursday, January 15, 2009 4:55 PM by Eric White - eric.white@av.abbott.com

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

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

Thursday, January 15, 2009 11:57 PM by Boris Yanushpolsky

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

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

Friday, March 06, 2009 10:56 AM by Desi

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

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker