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.
Comments
- Anonymous
September 26, 2007
Is there a similar way to put all computers in a group into maintenance mode? - Anonymous
November 01, 2007
Hello,i like just to notify that this script work not by me...I don´t know why.. - Anonymous
November 05, 2007
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 ??? - Anonymous
January 04, 2008
Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of - Anonymous
January 04, 2008
Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of - Anonymous
January 05, 2008
Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of - Anonymous
January 05, 2008
Maintenance mode expired, monitored server is still down, but there is no alert in the alert view of - Anonymous
February 20, 2008
HiI get an errorGet-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 - Anonymous
February 29, 2008
There are many articles that talk about maintenance mode in System Center Operations Manager 2007. Topics - Anonymous
April 20, 2008
http://www.ezedir.com/Article/Computers/ - Anonymous
July 12, 2008
Check out Boris Yanushpolsky's blog ( http://blogs.msdn.com/boris_yanushpolsky ). Boris is an SCOM - Anonymous
November 01, 2008
i like just to notify that this script work not by me...I don´t know why.. - Anonymous
November 12, 2008
Interesting post, thanks for a good read! - Anonymous
December 09, 2008
It is a major problem, glad to of found a solution. Thanks. - Anonymous
May 13, 2009
Our servicedesk is using an adapted version of the GroupMaintenancemode -script from Boris Yanushpolski - Anonymous
June 05, 2009
Is there a way to place a computer in maintenance via an asp.net page, instead of a powershell script ? - Anonymous
July 06, 2009
i was having same issue thnx for solving the problem. - Anonymous
October 22, 2009
How can I disable all 2740 alerts on SCOM 2007 that monitor Exchange 2007?