Quantcast
Viewing all articles
Browse latest Browse all 21975

Monitoring a remote service, then starting and sending notfification

Image may be NSFW.
Clik here to view.
You cannot vote on your own post
0

Hi-

I am a PS newbie so forgive me if this has been answered. We are migrating to SCOM2012 but have 1 2000 server that needs 1 service running on it. Since SCOM2012 can't monitor 2000 servers I need to monitor this service somehow. 

I am trying to write a Poweshell script that will:

1. Detect is the remote machine is up via PING, IF so proceed to step 2 if not then QUIT

2. Get the state of a service on a remote machine (i.e. Get-WmiObject -computer S00APP07 Win32_Service -Filter "Name='Messenger'") 
     If the service resturns a result of STARTED then quit otherwise proceed to step 3

3. Start the service and send an e-mail to me@company.com

4. Wait 30 seconds then goto STEP 2. 

So the result is that if the script finds the machine via ping it will then determine if the service is running or not. If the service is running the script will quit otherwise it will try to restar the service, send me an e-mail and then check again to see if the service is running.

I had this mostly running in a standard cmd shell script but the "IF STATE 4 GOTO :END" isn't working and I'd rather do it in powershell

Ping Server | find "Reply"
if errorlevel 1 echo NG && goto :END
:BEGIN
sc \\Server querymessenger | find "STATE"
IF STATE 4 GOTO :END

sendmail -f server@company.com -t admin@company.com -m THe service stopped and was sent a restart command via this batch file. This batch file will try to restart the service every 30 seconds until it is started. If you receive multiple copies of this e-mail the auto restarting of the service was not sucessful and needs manual intervention. -u X Service on Server -s EMAILSERVER


SC \\SERVER START MESSENGER 

PING -n 30 127.0.0.1 >nul 

sc \\Server query Messenger | find "STATE"
IF ERRORLEVEL 1 GOTO :BEGIN


:END

If you have a good poweshell script that would do this I would appreciate it.


Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>