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 (18)

  1. Reza says:

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

  2. Zied says:

    Hello,

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

  3. kobi says:

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

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

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

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

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

  8. Leif says:

    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

  9. SCOM/MOM says:

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

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

  11. parteisa says:

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

  12. Computer Repair says:

    Interesting post, thanks for a good read!

  13. trojan.vundo.h says:

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

  14. Mark Wolzak says:

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

  15. Filip says:

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

  16. dell gx620 says:

    i was having same issue thnx for solving the problem.

  17. Nir says:

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