One if the greatest things about working for a company like Microsoft is the number of people that work together to discuss, identify and solve problems. For this particular problem was just four of us ( Jeramy Evers, Mark Trammell, Paul Ray and myself ) discussing a better solution for administrators to place their servers in Maintenance Mode while they are on the server about to perform some type of work. Yes, yes I know there are plenty of scripts out there already that do something like this, but if there is a SCOM Agent already installed on it and it is healthy, then why not place it into Maintenance Mode from the server?
Here is is solution we came up with:
I am going to place this server into Maintenance Mode:
First we loaded the “Start-MaintenanceMode.ps1” either on the desktop or in a location that everyone has access to, or at least the system / application administrators. If you right click on the script and “Run with PowerShell”
When the PowerShell window pops open, it may ask you to change the “Execution Policy”. select “Y” if you would like to continue with setting the system in Maintenance Mode
When the “SCOMManagementServerName:” appears, enter one of the management servers.
The next thing that appears is the “Minutes:”, enter the amount of time you would like to place the system in Maintenance Mode. Note that you cannot place a system in maintenance mode less than 5 minutes.
If you see the following message, you shouldn’t worry to much since the script will call out and import the “operationsmanager” module.
If I go back to my Console I will see the system in Maintenance Mode
That is it.
If you want to require people to provide comments each time they place a system, you can change the “$False” to “$True” for line 56.
Pretty simple, you can download the script here.
This script has been tested and works fro SCOM 2012 R2 and SCOM 2016.