In SCOM 2016 there is a new way to set maintenance mode on your agent machine itself. Microsoft released a module to set the maintenance mode on the agent server itself. It uses a library (MaintenanceMode.dll) to set maintenance mode parameters on your monitored server. This DLL can be found in the C:\Program Files\Microsoft Monitoring Agent\Agent directory. After you executed the commands it will write some registry settings and after that, a rule in SCOM will pick these settings up and set the corresponding maintenance window in SCOM. If you want to read more details, please check this blog post from Natascia Heil.
This approach is a very nice way of doing maintenance mode, BUT there are some pains involved with this implementation. For example if you start to set a maintenance window, you will need to confirm each time to approve your request.
Let’s say you want to use a scheduled task and the Microsoft module to schedule a maintenance mode. Because the confirmation dialog is hardcoded it will be tricky to skip that confirmation. In addition it is somewhat limited, like resetting the maintenance mode settings (deleting the maintenance mode registry key) has to be done manually.
If have reverse engineered the DLL and created a PowerShell module to achieve the exact same functionality with the identical syntax and command. I added also a command to delete the maintenance settings (registry key) on the agent machine.
Install the module via PowerShell Gallery…
…then import the module and set the parameters…
…to delete the registry key use the following command…
As I mentioned before, it works exactly the same way as Microsoft describes in the TechNet article. But, except we can use this module to use in scheduled tasks and delete the settings via module.
If you have any questions, let me know. I hope this helps.