Scripting Maintenance Mode in SCOM 2012

2016-02-16 17:04:16
Posted by aeadmin on Feb 16, 2016 9:04:16 AM

 

Hello fellow SCOM’ers. Today, we wanted to share with you all an easy way to script maintenance mode in SCOM 2012. If you don’t want to manually run this, you can run it as a scheduled task. We like to manage this manually by running the script ourselves, but to each their own. Happy scripting!

Syntax

GroupMaintMode -ScomServer “<scomserver>” -GroupDisplayName “<groupname>” `
-DurationInMin 10  -Reason “<reasonformaint” -Comment “<comment>”

 

#--------Begin Sample Script----------------

#*****************************************************************************

# Name: SCOM 2012 Maint Mode PS Script

#

#  Parameters:

#

# -ScomServer: contians SCOM server name

# -GroupDisplayName: contains display name of the target group

# -DurationInMin: contains integer of desired duration in minutes

# -Reason: values are UnplannedOther, PlannedHardwareInstallation,

#           PlannedHardwareMaintenance, UnplannedHardwareMaintenance,

#           UnplannedHardwareInstallation, PlannedOperatingSystemReconfiguration,

#           UnplannedOperatingSystemReconfiguration, PlannedApplicationMaintenance,

#           ApplicationInstallation, ApplicationUnresponsive, ApplicationUnstable,

#           SecurityIssue, LossOfNetworkConnectivity

# -Comment: optional parameter

#*****************************************************************************

 

Function GroupMaintMode

#($ScomServer, $GroupDisplayName, $DurationInMin, $Reason, $Comment)

(

[Parameter(Mandatory=$true)][string]$ScomServer,

[Parameter(Mandatory=$true)][string]$GroupDisplayName,

[Parameter(Mandatory=$true)][Int32]$DurationInMin,

[Parameter(Mandatory=$true)][string]$Reason,

[Parameter(Mandatory=$false)][string]$Comment

){

 

Import-Module OperationsManager

New-SCOMManagementGroupConnection -ComputerName $ScomServer

 

ForEach ($Group in (Get-ScomGroup -DisplayName  $GroupDisplayName))

{

If ($group.InMaintenanceMode -eq $false)

{

$group.ScheduleMaintenanceMode([datetime]::Now.touniversaltime(), `

([datetime]::Now).addminutes($DurationInMin).touniversaltime(), `

 

"$Reason", "$Comment" , "Recursive")

}

}

 

}

Written and composed by one of our Senior Microsoft System Center Architects, Jessica Ervin-Hang

Tags: scom, PowerShell, system center

    Are You Secure? Score a FREE O365 Security Assessment.

    We're here to help!

    We'd love to find out more about the projects and initiatives you're working on to exchange ideas and provide some high-level guidance where we can.  We love learning from others as well as sharing some of our experience and lessons learned.  Let's talk!

    Subscribe to Email Updates

    Recent Posts

    Posts by Tag

    see all