Last active
December 13, 2015 21:28
-
-
Save Nate630/4977282 to your computer and use it in GitHub Desktop.
SCOM 2012 Maintenance Mode Powershell script ( put a SCOM 2012 group in Maintenance Mode for x hours)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Puts everything in a specific SCOM GROUP in Maintenance Mode for x hours | |
# | |
# I'm not sure where I got this....script. Sorry. | |
# | |
# Uncomment the 'param' line below if you want to pass values by parameter to this script | |
#param ($groupName, $MMDurationInHours, $rmsServerName) | |
$MMDurationInHours = "3" | |
$rmsServerName = "scom.domain.com" | |
$groupName = "Group Name you want to put in Maint Mode" | |
$comment = "Scheduled via windows server task on scom.domain.com" # this comment shows up in the SCOM Console. | |
#Load the Operations Manager snapin and connect to the Root Management Server | |
add-pssnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"; | |
Set-Location "OperationsManagerMonitoring::"; | |
$mgConn = New-ManagementGroupConnection -connectionString:$rmsServerName; | |
if($mgConn -eq $null) | |
{ | |
[String]::Format("Failed to connect to RMS on '{0}'",$rmsServerName); | |
return; | |
} | |
Set-Location $rmsServerName; | |
$startTime = [DateTime]::Now | |
$endTime = $startTime.AddHours($MMDurationInHours) | |
$MonitoringClassCG = get-monitoringclass | where {$_.DisplayName -eq $groupName} | |
$MonitoringGUID = get-monitoringobject $MonitoringClassCG.Id | |
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -comment:$comment -monitoringObject:$MonitoringGUID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment