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.
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
}
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
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
Thanks, this was extremely helpful!
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,
Sven
Make sure your group only contains objects of type “Web Applicaiton Perspective”
What object type(s) did you add to the custom group?
Objects of type Web Application Perspective.
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
If you have multiple watcher node for the same URL then script fill fail because multiple objects are being enumerated for that just add another foreach loop. Here is the working one;
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}
foreach ($eachurl in $URLWatcher)
{
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutes)
“Putting URL into maintenance mode”
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$eachurl -comment:$comment -Reason:$reason
}
}
Is this applicable to SCOM 2012 as well?
[…] As I have said in SCOM Trick 7, the use of maintenance mode is important. But not always will somebody use the normal SCOM interface (or web interface) to start maintenance mode right before they start working on the machine. To be honest a lot of the times machines get placed in maintenance mode when the alerts start flowing in during planned work and they quickly place the machine into maintenance mode. In any case, you can actually schedule maintenance mode, or include it in scripting. Here are some resources to get you started. Maintenance mode history report http://www.systemcentercentral.com/tabid/145/indexId/70867/Default.aspx Remote maintenance mode mp http://www.systemcentercentral.com/tabid/145/indexId/11577/Default.aspx by running a script on the agent, makes event log entry that gets picked up. MCS maintenance mode mp http://www.systemcentercentral.com/tabid/145/indexId/11546/Default.aspx Put a group into Maintenance Mode http://blogs.technet.com/b/operationsmgr/archive/2009/11/17/putting-a-group-of-computers-into-maintenance-mode-via-powershell.aspx Maintenance Mode powershell script http://blogs.technet.com/b/mgoedtel/archive/2009/10/29/updated-powershell-script-maintenance-mode.aspx Remote Maintenance Mode GUI tool https://www.scom2k7.com/scom-remote-maintenance-mode-scheduler-20/ Cluster and maintenance mode http://blogs.msdn.com/b/mariussutara/archive/2008/09/05/cluster-and-maintenance-mode.aspx Stopping maintenance mode http://blogs.msdn.com/b/boris_yanushpolsky/archive/2007/08/30/stoping-maintenance-mode.aspx SCOM Maintenance Mode Tool http://scommaintenancemode.codeplex.com/ Schedule a group of URLs (or one) into maintenance mode https://www.scom2k7.com/schedule-a-group-of-urls-into-maintenance-mode/ […]