Infrastructure

Using PowerShell for maintenance mode with noncomputer classes in Operations Manager 2012

Are you looking for a way to put objects other than computers into maintenance mode in Operations Manager 2012 R2? The PowerShell scripts are different for these between Operations Manager 2007 and 2012. The following are what we put together to put various items into maintenance mode. These include starting maintenance mode for the following items:

  • Maintenance Mode for a synthetic web test in Operations Manager 2012
  • Maintenance Mode for a synthetic web test in Operations Manager 2007
  • Maintenance Mode for a service monitor in Operations Manager 2012

 

Maintenance Mode for a synthetic web test in Operations Manager 2012:

The following PowerShell script prompts for the name of a web application and puts the perspective into maintenance mode for the next 90 minutes.

 

# Ask user for input

$strWebApp = Read-Host "Enter the Web Application name"

# Get class object

$objMonClass = get-scomclass | where { $_.Name -eq "Microsoft.SystemCenter.WebApplication.Perspective"}

# Connect object and add Maintenance Window

get-scomclassinstance | Where-Object { $_.DisplayName -match $strWebApp } | Start-SCOMMaintenanceMode -EndTime: ((Get-Date).AddMinutes(90)) -Comment: "Server maintenance"

 

[The script above was built from what is available at http://michielw.blogspot.com/2009/03/scom-maintenance-mode-with-powershell.html for 2007 and updated to 2012]

 

Maintenance Mode for a synthetic web test in Operations Manager 2007:

See http://michielw.blogspot.com/2009/03/scom-maintenance-mode-with-powershell.html for this script.

 

Maintenance Mode for a service monitor in Operations Manager 2012:

The following PowerShell script prompts for the name of a service and puts it into maintenance mode for the next 90 minutes.

 

# Ask user for input

$strServiceApp = Read-Host "Enter the service name"

# Get class object

$objMonClass = get-scomclass | where { $_.Name -eq "Microsoft.SystemCenter.Service"}

# Connect object and add Maintenance Window

get-scomclassinstance | Where-Object { $_.DisplayName -match $strServiceApp } | Start-SCOMMaintenanceMode -EndTime: ((Get-Date).AddMinutes(90)) -Comment: "Server maintenance"

 

Additional reference:

http://www.opsmanager.se/2011/10/25/maintenance-mode-with-powershell-in-scom-2012/

http://msdn.microsoft.com/en-us/library/hh329080.aspx

http://social.technet.microsoft.com/Forums/systemcenter/en-US/31c6a460-68c6-4e10-9742-f9fc6b243837/scom-2012-getting-list-of-objects-in-maintenance-mode?forum=operationsmanagergeneral

http://blogs.technet.com/b/markmanty/archive/2012/05/14/scom-maintenance-mode-setting-for-list-of-servers.aspx

Leave a Reply

x

We use cookies to ensure the best possible experience on our website. Detailed information on the use of cookies on this site is provided in our Privacy and Cookie Policy. Further instruction on how to disable our cookies can be found there.