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

11 Responses to Schedule a URL into Maintenance Mode

  1. Jonathan Phillips February 18, 2009 at 6:23 pm #

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

  2. Marnix Wolf April 16, 2009 at 5:05 am #

    Great script Tim. Thanks!
    Best regards,
    Marnix Wolf

  3. Paul B November 11, 2009 at 3:41 pm #

    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 November 12, 2009 at 2:20 pm #

    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 November 12, 2009 at 4:22 pm #

    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. Lewis July 3, 2012 at 7:49 am #

    Please Assist not sure what is wrong

    I am doing the following steps….

    Using Web Application Transaction Monitoring
    Add monitoring Wizard
    Web Application Transaction Monitoring
    Give A name and Select a custom mgmt pack
    Type the URL http://www.hotmail.com and Click Test
    Select a Watch node.

    I add another URL using the above method
    Url: http://www.google.com

    So now i have 2 URL for monitoring

    Next i create a custom group called “URL monitoring”
    using “Objects of type Web Application Perspective”, i add both the names.

    Then i run the powershell command

    C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe c:\URLGroupMM.ps1 -rootMS: ‘FhGscomprod’ -GroupName: ‘URL Monitoring’ -minutes:5 -comment: ‘My Comment’ -reason: ‘PlannedOther’

    I still get an error….

    You cannot call a method on a null-valued expression.
    At C:\URLGroupMM.ps1:10 char:56
    + $groupagents = $groupObject.getrelatedmonitoringobjects <<<< ()
    + CategoryInfo : InvalidOperation: (getrelatedmonitoringobjects:String) [], RuntimeException
    + FullyQualifiedErrorId : InvokeMethodOnNull

    Putting URL into maintenance mode
    New-MaintenanceWindow : Cannot bind argument to parameter 'MonitoringObject' because it is null.
    At C:\URLGroupMM.ps1:27 char:81
    + New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject: <<<< $URLWatcher -comment:$comment –
    Reason:$reason
    + CategoryInfo : InvalidData: (:) [New-MaintenanceWindow], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.EnterpriseManagement.Operations
    Manager.ClientShell.NewMaintenanceWindowCmdlet

  7. Ryan Boender July 16, 2014 at 10:48 am #

    Will your maintenance mode scheduler put a URL in maintenance mode?

    • Tim McFadden July 16, 2014 at 10:53 am #

      Yes just pick the Class for the URL and the Object under the class tab

Trackbacks/Pingbacks

  1. Scheduled Maintenance Mode for Web Monitors « System Center Operations Manager 2007 R2 - April 3, 2010

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

  2. Schedule a URL into Maintenance Mode « TechColumnist - July 7, 2010

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

  3. Schedule a URL into Maintenance Mode | Revolusionline - December 5, 2011

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

Leave a Reply