Skip to content

Instantly share code, notes, and snippets.

@Nate630
Last active December 13, 2015 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nate630/4977282 to your computer and use it in GitHub Desktop.
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)
#
# 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