Here is the script (SCOM 2007 maintenance mode):
param($rootMS,$minutesMM,$comment,$textFile)
$servername = Get-Content $textFile
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client" -ErrorVariable errSnapin
Set-Location "OperationsManagerMonitoring::" -ErrorVariable errSnapin
new-managementGroupConnection -ConnectionString:$rootMS -ErrorVariable errSnapin
set-location $rootMS -ErrorVariable errSnapin
foreach ($srv in $servername) {
$computerPrincipalName = $agent.displayname
$computerPrincipalName
$computerClass = get-monitoringclass -name:Microsoft.Windows.Computer
$computerCriteria = "PrincipalName='" + $computerPrincipalName + "'"
$Computer = Get-MonitoringObject -monitoringclass:$ComputerClass | where {$_.PathName -match $srv}
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($minutesMM)
"Putting " + $computer + " into maintenance mode"
New-MaintenanceWindow -startTime:$startTime -endTime:$endTime -monitoringObject:$computer -comment:$comment
}It reads a text file and puts each server from that text file into maintenance mode. It does each server one at a time and only goes to the next one after the previous one has finished. You can imagine this can take a while with a lot of servers. Does anyone know a way to speed it up?