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
Jonathan Phillips:
Great post. This script came in handy. I converted it for use in my environment including the HeatlhService and HealthServiceWatcher objects.
18 February 2009, 6:23 pmMarnix Wolf:
Great script Tim. Thanks!
16 April 2009, 5:05 amBest regards,
Marnix Wolf
Paul B:
I ran into this error when trying to run this from a powershell command prompt:
Can you give me any insite on why this is happening?
New-MaintenanceWindow : Cannot convert ‘System.Object[]‘ to the type ‘Microsoft.EnterpriseManagement.Monitoring.Monitor
ingObject’ required by parameter ‘MonitoringObject’. Specified method is not supported.
At C:\MaintenanceModeV4\URLMaintenanceModeV4.ps1:17 char:81
+ New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$ <<<< URLWatcher -comment:$comment -
Reason:$reason
Thanks for the creation of these scripts they are very hnady.
11 November 2009, 3:41 pmPaul B:
It looks like I can’t do multiple objects with the same name. I may have to do this by monitoring object id.
12 November 2009, 2:20 pmPaul B:
Ok.. I figured it out. Since I am new to scripting it took me awhile, plus some help from co-workers..
I added a foreach statement to repeat through the objects
foreach ($name in $URLWatcher) {
12 November 2009, 4:22 pmNew-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$name -comment:$comment -Reason:$reason }
Scheduled Maintenance Mode for Web Monitors « System Center Operations Manager 2007 R2:
[...] http://www.scom2k7.com/schedule-a-into-url-maintenance-mode/ [...]
3 April 2010, 1:00 pmSchedule a URL into Maintenance Mode « TechColumnist:
[...] http://www.scom2k7.com/schedule-a-into-url-maintenance-mode/ Share and Enjoy: [...]
7 July 2010, 6:54 pm