PowerShell Scipt: Restart OpsMgr 2012 Services

So I have been having a pesky time tracking out exactly why after normal OS patching and reboot SCOM 2012 email notifications get hung up. It doesn’t happen every time the server reboots and it doesn’t occur on service restarts either.  Nothing in the event logs to show why they wouldn’t be working properly. Since I cannot reproduce the issue on command, I had to create a bandaid to keep the notifications going out as expected.

So, below is my short term solution. I added the this script to a Scheduled Task to run on start-up.  This way the server will restart the services shortly after reboot occurs such as with WSUS Patching.  This will at least keep the notifications flowing until I can find the culprit.

###################################################
## OpsMgr_ServiceRestart.ps1
## Version 1.1
## PowerShell Script to restart services OpsManager 2012 Services. This can be used in
## conjuncture with Scheduled Task to restart services after a reboot
##
##
## Author: Josh Ancel
## Date Written: 9/13/2013
##
##
###################################################
#Stopping Services System center Data Access(OMSDK), System Center Manament APM, and System Center Managment(HealthService)
##Write-Host "Stopping Services"
stop-service omsdk, 'System Center Management APM'
start-sleep -s 45
##Write-Host "Waiting..."
stop-service HealthService
##Write-Host "Waiting 3.5 min before starting services...."
start-sleep -s 210
# Start Services
##Write-Host "Starting Services"
Start-service HealthService
##Write-Host "Waiting 3.5 min......again....."
start-sleep -s 210
start-service omsdk, 'System Center Management APM'
##Write-Host "Completed"</code>

#EOF

I thought others might find the script handy so I shared. As with all my scripts feel free to use it, abuse it, or even fuse it.

Good Luck!

Advertisements

~ by Josh on September 13, 2013.

3 Responses to “PowerShell Scipt: Restart OpsMgr 2012 Services”

  1. It’s a bummer to hear that you are having that problem. That’s a real headscratcher that could drive a guy insane. Thanks for the script. I’ve not encountered this but I use a command channel with a highly modified version of Tao Yang’s email script, not the ootb email channel.

    • That might not be a bad idea to alter my command channel. However I suspect that the real issues is caused when the SQL server is pulled out from under the Management Servers. OpsMgr is suppose to recover from this will little or no issue in 2012, and it has been doing so for some time in my case, however I think that I may have crossed some sort of a threshold with the number of target and Management Servers that is causing it to not recover as cleanly.

  2. […] why I kept getting the SQL reconnect issue with Ops Manager 2012 that I was having here – Powershell Script to restart SCOM. It turns out that by default Ops Manager 2012 does not automatically try to reconnect to its SQL […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s