The System Center Operations Manager Support Team Blog

This is the OpsMgr 2007 blog for the Microsoft support team. If you were looking for the SCOM 2007 or MOM 2005 blog then you are in the right place.

Putting a Group of Computers into Maintenance Mode via Powershell

Putting a Group of Computers into Maintenance Mode via Powershell

  • Comments 4
  • Likes

image Have you ever found yourself in need of putting a group of systems into Maintenance Mode in System Center Operations Manager 2007 R2?  If so you can use the script below.  Note that in SCOM 2007 R2 there is no need to put the health service and health service watcher into Maintenance Mode separately, we just need to put the computer itself into Maintenance Mode and it will take care of other components automatically.



Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
set-location $rootMS -ErrorVariable errSnapin;

$groupObject = get-monitoringobject | where {$_.DisplayName -eq $group};
$groupagents = $groupObject.getrelatedmonitoringobjects()

foreach ($agent in $groupAgents)


$computerPrincipalName = $agent.displayname

$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 | Where{$_.Displayname -like $computerPrincipalName}
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddHours($numberOfHoursInMaintenanceMode)

"Putting " + $computerPrincipalName + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment



Save the above script with a ps1 extension.

Schedule the script using the Task Scheduler and command line below:

Powershell c:\MMode.ps1 -rootMS: <RMS server name> -group: <Group name> - Numberofhoursinmaintenancemode: 1 -Comment: 'This is a test'

Hope this helps,

Ritesh Grover | System Center Technical Lead

  • Hello,

    Is there a way to input the name of prompt the user to enter the name of the group each time the script is run. For example what I would like to do is add this script as a Task under Windows Computer view. Then when executed a a popup appears asking for the name of the group (or better still selection from a drop down list (pre populated list) group name is typed in or selected and OK pressed etc to execute.

    Thanks very much


  • I would really like to do something similar, where the script would point to a text file with a list of servers.  It would place all servers in that file, into Maintenance Mode.

    Is this possible?  We are currently doing this with MOM2005.

  • Your thought processing is wonderful. The way you tell the thing is awesome. You are really a master. Great Blog!! That was amazing

    <a href="" title= “Mobile Repair” ><b>Mobile Repair

  • Has anyone tried this on OM 2012? I need a PS script to put servers into Maintenance mode on 2012. Thanks!

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment