Schedule a URL into Maintenance Mode

I needed to schedule a URL into Maintenance Mode this week and couldn’t find any scripts or examples so I created my own.


param($rootMS,$urlName,$minutes,$comment,$reason)

Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin;

Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin;
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin;
set-location $rootMS -ErrorVariable errSnapin
;

$URLWatcher = (Get-MonitoringClass -name Microsoft.SystemCenter.WebApplication.Perspective) | Get-MonitoringObject | where {$_.DisplayName -eq $urlName}

$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutes)


"Putting URL into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$URLWatcher -comment:$comment -Reason:
$reason

 
Usage:

C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe URLMaintenanceModeV4.ps1 -rootMS: `SCOMRMS1′ -urlName: ‘MSN Website Checker’ -minutes:45 -comment: ‘My Comment’ -reason: ‘PlannedOther’

 

Download: URLMaintenanceModeV4.zip

Leave a comment