Quick bit of script to put a monitored service on a specific server into MM

Hi, one of our Developers has asked for some script they can add to their deployment that will put a particular monitored service on a specific server into MM for a set amount of time and then check the status afterwards to make sure it is running. Has anyone got anything handy?

3 Likes

One way is to use the PowerShell script here, and put the specific service as the only item in a group. Running the script will put the service into maintenance mode for the specified duration. I don’t know if you could replace the group elements in the script with the actual service, that would have to be tested, and may not be worth the hassle when the group works.

Also, the status is apparent as, when it comes out of maintenance mode, it will automatically raise an alert if it isn’t running. Or someone else with better PowerShell knowledge can suggest a modification to report the status.

OpsMgr 2012: Group Maintenance Mode via PowerShell (the way it should be)
1 Like
Ehrnst – 5 hours ago

You don’t have to install the console, but you do need to load the module. You can copy the files out of your server and add them to a share or something. import the module with unc path, import-module \myserver\psmodule\operationsmanager\OperationsManager.psd1Another alternative is to run your script in a console task, but this isn’t available trough squaredup or you can develop your own tool.

Personally, depending on how often this happpens or if it’s technically possible for the application, i would just disable the service, which also supress monitoring. and enable it when done
 

sc config “Servicename” start=demand

sc config “Servicename” start=auto

1 Like

Hi Matthew. Where do you plan to execute this script? Initating MM from the agent it self isnt possible unless you install/load the SDK assembly and query your management server through Powershell - Not ideal. If i read through the lines, this is a windows service monitored by SCOM and generates an alert when the server reboots etc because the monitored object/service is taking more time to load than the agent’s healthservice?

Thanks for your reply. This is a custom Windows service that the developers stop, deploy code and then restart. The service is usually down for around 5 minutes which causes a service stopped alert and then a closed alert that they are trying to avoid. We can install the Ops Console on the machine they deploy from so they can use import-module Operations Manager,

You don’t have to install the console, but you do need to load the module. You can copy the files out of your server and add them to a share or something. import the module with unc path, import-module \myserver\psmodule\operationsmanager\OperationsManager.psd1

Another alternative is to run your script in a console task, but this isn’t available trough squaredup or you can develop your own tool.

Personally, depending on how often this happpens or if it’s technically possible for the application, i would just disable the service, which also supress monitoring. and enable it when done

Thanks, I think that actually makes most sense. I’ll just use the below. As this is a comment I can’t mark as answer.

sc config “Servicename” start=demand

sc config “Servicename” start=auto

HI Matthew, in this scenario it would be great if you could answer your own question with the above and mark it as the best answer :slight_smile: