Place A Server Into Maintenance Mode From That Server without a Console - Start-MaintenanceMode.ps1

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:

image


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”

image

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'"

image

cut and paste the shortcut to the in the “C:\Users\Public\Desktop” folder.

image

You should see the shortcut on your desktop now

image

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

image

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”

image

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

image

When the “SCOMManagementServerName: ” appears, enter one of the management servers.

image

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.

image

If you see the following message, you shouldn’t worry to much since the script will call out and import the “operationsmanager” module.

image

If I go back to my Console I will see the system in Maintenance Mode

image

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.

image

Pretty simple, you can download the script here.

This script has been tested and works fro SCOM 2012 R2 and SCOM 2016.

Comments

  • Anonymous
    February 09, 2018
    It seems like there are still a lot of dependencies. If the local machine doesn't have the SCOM console installed, and thus doesn't have the Operations Manager module, you need to have rights to open a PS remoting session. In either case, you have to have the right to establish a new SCOM Management Group Connection.It's a shame that MMWeb was not written with automation more in mind.
    • Anonymous
      February 09, 2018
      The comment has been removed
  • Anonymous
    March 05, 2018
    Work for a large financial institution, use this script quite often doing adhoc remediation. Just deployed some security clients with services to 1200 servers and it worked Like a champ.Good job - Thanks for making this easier for us.