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


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:


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

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

  2. 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 –

    Thanks for the creation of these scripts they are very hnady.

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

  4. 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 –
    + CategoryInfo : InvalidData: (:) [New-MaintenanceWindow], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.EnterpriseManagement.Operations

Leave a Reply

Your email address will not be published. Required fields are marked *