How to Get the List of All the Computers in Maintenance Mode in System Center Operations Manager 2007

How to Get the List of All the Computers in Maintenance Mode in System Center Operations Manager 2007

Here's a cool tip from Ritesh Grover, one of Microsoft's excellent support engineers on the Operations Manager team.  If you're looking for a script to quickly get a list of the computers that are in Maintenance Mode then this should do the trick:

========

To get a list of all computers and components that are in Maintenance Mode, copy and paste the below script in .ps1 format and run the script from an OpsMgr 2007 PowerShell console.  If a specific component is not in Maintenance Mode then it will give you an error for that component:

***************************Script Starts****************************
$Group='All Computers'

$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 -criteria:$computerCriteria

$healthServices = $computer.GetRelatedMonitoringObjects($healthServiceClass)

$healthService = $healthServices[0]

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

$healthServiceWatcher = get-monitoringobject -monitoringclass:$healthServiceWatcherClass -criteria:$healthServiceCriteria
Write-host "****************************"
$agent.displayname
Write-host "****************************"
Write-host " "

Write-host "Computer"
Write-host " "
Get-MaintenanceWindow -monitoringobject:$Computer

Write-host "Health Service"
Write-host " "
Get-MaintenanceWindow -monitoringobject:$HealthService

Write-host "HealthServiceWatcher"
Write-host " "
Get-MaintenanceWindow -monitoringobject:$healthservicewatcher

}

***********************************END Script**************************************

Sample Output:

****************************
ComputerName.DomainSMS.com
****************************

Computer

Get-MaintenanceWindow : The MonitoringObject is not in maintenance mode.
At C:\mw.ps1:37 char:22
+ Get-MaintenanceWindow  <<<< -monitoringobject:$Computer

Health Service

Get-MaintenanceWindow : The MonitoringObject is not in maintenance mode.
At C:\mw.ps1:41 char:22
+ Get-MaintenanceWindow  <<<< -monitoringobject:$HealthService

HealthServiceWatcher

MonitoringObjectId : 81c07224-ea63-3206-937f-77d1efc29c86
StartTime          : 10/14/2008 11:40:40 PM
ScheduledEndTime   : 10/15/2008 12:10:40 AM
EndTime            :
Reason             : UnplannedOther
Comments           :
User               : DOMAINSMS\OpsAdmin
LastModified       : 10/14/2008 11:40:40 PM
ManagementGroup    : MGLab
ManagementGroupId  : 3c3c8575-97dc-4e54-b4cc-1fffecffb7bf

So for the computer ComputerName in the above example output, Computer and Health Service error out but  HealthServiceWatcher gave valid data as only HealthServiceWatcher was in Maintenance Mode.

Note that the script above will check all the computers.  If you want to check for specific computers replace the $Group variable value with the group you wish to check.

Leave a Comment
  • Please add 8 and 5 and type the answer here:
  • Post
Wiki - Revision Comment List(Revision Comment)
Sort by: Published Date | Most Recent | Most Useful
Comments
  • Fernando Lugão Veltem edited Revision 3. Comment: remove en-us from title

  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

Page 1 of 1 (2 items)
Wikis - Comment List
Sort by: Published Date | Most Recent | Most Useful
Posting comments is temporarily disabled until 10:00am PST on Saturday, December 14th. Thank you for your patience.
Comments
  • Craig Lussier edited Revision 2. Comment: added en-US to tags and title

  • Fernando Lugão Veltem edited Revision 3. Comment: remove en-us from title

Page 1 of 1 (2 items)