Maintenance Mode via Powershell Remoting
There are loads of scripts and GUIs that you can use to set Maintenance Mode in OpsMgr, but if you want to do this from a server that doesn’t have the OpsMgr-snapins for Powershell it’s a bit harder…
But then there is Powershell v2 and Remoting… It gives you the option to run a scriptblock on another computer…
Just enable remoting on your RMS and then try this script from another machine:
Function setMaintMode {
PARAM (
[string] $rmsHostname,
[string] $agentName,
[string] $Comment,
[string] $Reason,
[int] $Time
)
Invoke-Command -ComputerName $rmsHostname -scriptblock {
PARAM (
[string] $agentName,
[string] $Comment,
[string] $Reason,
[int] $Time
)
Add-PSSnapin "Microsoft.EnterpriseManagement.OperationsManager.Client"
Set-Location "OperationsManagerMonitoring::"
New-ManagementGroupConnection -ConnectionString:localhost | Out-Null
$computerClass = Get-MonitoringClass -name:Microsoft.Windows.Computer
$computerCriteria = "PrincipalName='" + $agentName + "'"
$computer = get-monitoringobject -monitoringclass:$computerClass -criteria:$computerCriteria
if ($computer.InMaintenanceMode -eq $false) {
$startTime = [System.DateTime]::Now
$endTime = $startTime.AddMinutes($Time)
New-MaintenanceWindow -startTime $startTime -endTime $endTime -Comment $comment -Reason $Reason -monitoringObject $computer
return $true
} else {
# Allready in maintenance mode
return $false
}
} -ArgumentList $agentName, $Comment, $Reason, $Time
}
setMaintMode -rmsHostname "rmsserver.domain.local" -agentName "currentserver.domain.local" -Comment "Some comment" -Time 30 -Reason "PlannedOperatingSystemReconfiguration"
What it does is that it run’s the OpsMgr-specific parts on the RMS instead on your local machine… so with that in place it’s easy to create a GUI around it and then spread a shortcut to all your servers that have Powershell v2 installed.
Notes:
The quick and dirty way to enable remoting on your rms, start cmd as an administrator and run winrm quickconfig
Here can you find a quick intro to PS Remoting.


