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