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

7 Comments

  1. Jonathan Phillips:

    Great post. This script came in handy. I converted it for use in my environment including the HeatlhService and HealthServiceWatcher objects.

  2. Marnix Wolf:

    Great script Tim. Thanks!
    Best regards,
    Marnix Wolf

  3. 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.

  4. Paul B:

    It looks like I can’t do multiple objects with the same name. I may have to do this by monitoring object id.

  5. Paul 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) {
    New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$name -comment:$comment -Reason:$reason }

  6. Scheduled Maintenance Mode for Web Monitors « System Center Operations Manager 2007 R2:

    [...] http://www.scom2k7.com/schedule-a-into-url-maintenance-mode/ [...]

  7. Schedule a URL into Maintenance Mode « TechColumnist:

    [...] http://www.scom2k7.com/schedule-a-into-url-maintenance-mode/ Share and Enjoy: [...]

Leave a comment