Schedule a group of URLs into Maintenance Mode
I needed to schedule a group of URLs into Maintenance Mode. I already created a script to schedule one URL but setting up 30 would be a pain to manage. So I created a new script to schedule a group of URLs.
[ad#adlink]
URLGroupMM.zip
Usage:
C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe C:\URLGroupMM.ps1 -rootMS scomrms1 -group ‘AU 3AM Website Reboot Group’ -minutes 120 -comment ’3AM AU Websites Reboot’ -reason ‘PlannedOther’
param($rootMS,$groupName,$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;
$groupObject = get-monitoringobject | where {$_.DisplayName -eq $groupName};
$groupagents = $groupObject.getrelatedmonitoringobjects()
foreach ($agent in $groupAgents)
{
$URLStuff = $agent.displayname
$URLStuff
$URLWatcher = (Get-MonitoringClass -name Microsoft.SystemCenter.WebApplication.Perspective) | Get-MonitoringObject | where {$_.DisplayName -eq $URLStuff}
$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
}
MatthiasR:
Hi Tim,
thank you for sharing this.
There is a mistake at the code:
$groupObject = get-monitoringobject | where {$_.DisplayName -eq “AU 3AM Website Reboot Group”};
The group name should be replaced with the variable “$groupName”
Regards
Matthias
11 February 2009, 10:37 amTim:
MatthiasR
Good eyes. I put that in there to test it and forgot to change it back. I have fixed the zip and the post.
Thanks,
Tim
11 February 2009, 10:49 amPaul:
Thanks, this was extremely helpful!
17 October 2009, 6:19 pmSven:
I tried this URL group maintenance mode powershell script and it doesn’t appear to work.
I am getting the following error:
You cannot call a method on a null-valued expression.
At D:\Temp\URLGroupMM.ps1:9 char:56
+ $groupagents = $groupObject.getrelatedmonitoringobjects( <<<< )
Putting URL into maintenance mode
New-MaintenanceWindow : Cannot bind argument to parameter 'MonitoringObject' be
cause it is null.
At D:\Temp\URLGroupMM.ps1:26 char:81
+ New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObje
ct:$ <<<Powershell D:\Temp\URLGroupMM.ps1 -rootMS rtprms01.americas.ppdi.local -group ‘DMART Web Application Monitor Group’ -minutes 30 -reason ‘Daily maintenance mode’
Thanks,
22 February 2010, 10:58 amSven
Jacob:
What object type(s) did you add to the custom group?
24 March 2010, 8:28 amTim:
Objects of type Web Application Perspective.
27 April 2010, 7:02 pmTim:
Make sure your group only contains objects of type “Web Applicaiton Perspective”
27 April 2010, 7:07 pm