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” into the “C:\Temp” directory or a location of your choosing, keep in mind if you do change the location other than “C:\Temp”, you’ll have to modify the paths if you do change it.
The we create a short and then copied it to the in the “C:\Users\Public\Desktop” folder, which is hidden, you should be able to get to it by typing it into the explorer.
To create a shortcut, right click on the desktop and select “New” from the menu and click on “Shortcut”
Update the highlighted text and past it into the “Type the location of the item:” field
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". C:\Temp\Start-MaintenanceMode.ps1 -SCOMManagementServerName Your Management Server FQDN -ComputerToPlaceInMaintenanceMode localhost -Minutes 120 -Comment 'Applying Windows Updates'"
Here is mine
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -command ". C:\Temp\Start-MaintenanceMode.ps1 -SCOMManagementServerName 021scocsatl.contoso.com -ComputerToPlaceInMaintenanceMode localhost -Minutes 120 -Comment 'Applying Windows Updates'"
cut and paste the shortcut to the in the “C:\Users\Public\Desktop” folder.
You should see the shortcut on your desktop now
Now if you right click on the shortcut and either run with “PowerShell” or “Run As Administrator” to place the server in Maintenance Mode. you will see in your Console the server is in Maintenance Mode
Another options is utilizing the GPO to have it placed on all the servers automatically and making available
For the more advance users, 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.