Welcome to MSDN Blogs Sign in | Join | Help

Putting a computer into maintenance mode

Putting a computer into maintenance mode is what users do when they know a particular computer will be offline for a while (security update, known network issues, hardware installation, other things). This is done so that OpsMgr does not generate any alerts about this computer. The interesting part is that OpsMgr will still generate one particular alert. This has to do with the fact that the management server is not getting heart beats from the agent. In order to avoid the alert, you need to put the instances of HealthService and HealthServiceWatcher that are associated with that computer into maintenance mode as well.

 Here is a script that based on a computer name, number of hours to be in maintenance mode and a comment will put all the right pieces into maintenance mode:

 

param($computerPrincipalName,$numberOfHoursInMaintenanceMode,$comment)

 

$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer

 

$healthServiceClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthService

 

$healthServiceWatcherClass = get-monitoringclass -name:Microsoft.SystemCenter.HealthServiceWatcher

 

$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"

 

$computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria

 

$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)

 

$healthService = $healthServices[0]

 

$healthServiceCriteria = "HealthServiceName='" + $computerPrincipalName + "'"

 

$healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria

 

$startTime = [System.DateTime]::Now

 

$endTime = $startTime.AddHours($numberOfHoursInMaintenanceMode)

 

"Putting " + $computerPrincipalName + " into maintenance mode"

New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment

 

"Putting the associated health service into maintenance mode"

New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthService -comment:$comment

 

"Putting the associated health service watcher into maintenance mode"

New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$healthServiceWatcher -comment:$comment

 

In order to run this script you will need to do the following:

1 - Save to a a file (C:\MaintenanceMode.ps1)

2 - Open up the OpsMgr Command Shell

3 - Type the following:

C:\MaintenanceMode.ps1 -computerPrincipalName:"dc.contoso.com" -numberOfHoursInMaintenanceMode:4 -comment:"test"

The computerPrincipalName should contain the FQDN of the computer (for computers that are domain members) which you wish to put into maintenance mode.

Published Wednesday, July 25, 2007 10:28 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: Putting a computer into maintenance mode

Wednesday, September 26, 2007 7:15 PM by Reza

Is there a similar way to put all computers in a group into maintenance mode?

# re: Putting a computer into maintenance mode

Friday, November 02, 2007 6:18 AM by Zied

Hello,

i like just to notify that this script work not by me...I don´t know why..

# re: Putting a computer into maintenance mode

Monday, November 05, 2007 8:58 AM by kobi

Hi Boris,

After i put a computer in maintenance mode for one hour using the script. the computer isn't go out, and in the console it appears in maintenance mode until i manually stop it . any idea ???

# Maintenance Mode And Server Availability

Friday, January 04, 2008 2:39 PM by Notes on System Center Operations Manager

Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of

# Maintenance Mode And Server Availability

Friday, January 04, 2008 3:10 PM by Noticias externas

Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of

# Maintenance Mode And Server Availability (Another Solution)

Sunday, January 06, 2008 12:04 AM by Notes on System Center Operations Manager

Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of

# Maintenance Mode And Server Availability (Another Solution)

Sunday, January 06, 2008 1:00 AM by Noticias externas

Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of

# re: Putting a computer into maintenance mode

Thursday, February 21, 2008 7:26 AM by Leif

Hi

I get an error

Get-MonitoringClass : The 'Path' parameter is empty or the required provider location is not set."

I don't know what the "Path" param should be.

BR.

Leif

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

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

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

# re: Putting a computer into maintenance mode

Sunday, April 20, 2008 5:05 PM by Dave

# 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: Putting a computer into maintenance mode

Saturday, November 01, 2008 3:38 PM by parteisa

i like just to notify that this script work not by me...I don´t know why..

# re: Putting a computer into maintenance mode

Wednesday, November 12, 2008 2:07 PM by Computer Repair

Interesting post, thanks for a good read!

# re: Putting a computer into maintenance mode

Tuesday, December 09, 2008 8:50 AM by trojan.vundo.h

It is a major problem, glad to of found a solution. Thanks.

# Rights in the OpsMgr Shell

Thursday, May 14, 2009 4:15 AM by Mark Wolzak

Our servicedesk is using an adapted version of the GroupMaintenancemode -script from Boris Yanushpolski

# re: Putting a computer into maintenance mode

Friday, June 05, 2009 10:00 AM by Filip

Is there a way to place a computer in maintenance via an asp.net page, instead of a powershell script ?

# re: Putting a computer into maintenance mode

Monday, July 06, 2009 9:53 AM by dell gx620

i was having same issue thnx for solving the problem.

# re: Putting a computer into maintenance mode

Thursday, October 22, 2009 5:03 PM by Nir

How can I disable all 2740 alerts on SCOM 2007 that monitor Exchange 2007?

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker