≡ Menu

Powershell: How to get the SCOM maintenance mode history of a computer

Today I got a requirement to see if a computer account was placed in maintenance mode or yesterday. If yes, I would like to see maintenance window details and the username who did it.

Given that there no GUI option in SCOM to get this information, I explored the powershell way and finally came-up with below script.

function Get-SCOMMaintenanceModeHistroy {            

param (            


Add-PSSnapin Microsoft.EnterpriseManagement.OperationsManager.Client -ErrorAction 0 | Out-Null            
new-managementGroupConnection -ConnectionString:$RootmanagementServer | out-null            
Push-Location -Path "OperationsManagerMonitoring::" -ErrorAction:Stop               
$agent = Get-Agent | Where-Object {$_.displayname -match $ComputerName}            
$MaintenanceObj = Get-MaintenanceWindow -MonitoringObject $agent.HostComputer -History -ErrorAction 0            
  if($MaintenanceObj) {            
   $output = New-Object -Type PSObject -Property @{            
    ComputerName = $Computername            
    StartTime  = ($MaintenanceObj.Starttime).tolocaltime()            
    EndTime   = ($MaintenanceObj.ScheduledEndTime).Tolocaltime()            
    UserName  = $MaintenanceObj.User            
    Comment   = $MaintenanceObj.Comments            
   $Output | select ComputerName, StartTime, EndTime, UserName, Comment | ft -wrap            
  } else {            
   write-Error "Unable to get the maintenance mode of $ComputerName"            

There are some SQL queries around the web and you can use them if you want. You can find one such thing at http://sys-man.blogspot.com/2011/03/scom-2007-r2-maintenance-mode-history.html. I am not sure about the functionality of this SQL code. Please get this tested in test bed before you try in production.

Hope this helps and happy learning…

{ 2 comments… add one }
  • mikajlo October 13, 2015, 2:05 pm

    ComputerName = $Computer –> ComputerName = $ComputerName


    • TechiBee October 13, 2015, 6:30 pm

      Thanks for highlighting that. Corrected it now.

Leave a Comment