Solved

powershell script to check window service status if stopped start the service and send the status email to multiple users . status must be failure or success

Posted on 2015-01-03
2
3,177 Views
Last Modified: 2015-01-09
powershell script to check window service status if stopped start the service and send the status email to multiple users . status must be failure or success
0
Comment
Question by:Mickail
2 Comments
 
LVL 68

Accepted Solution

by:
Qlemo earned 500 total points
ID: 40530106
$MailParm = @{
  SmtpServer = 'smtp.yourdomain.com'
  From = 'you@yourdomain.com'
  To = 'you@yourdomain.com'
  Subject = 'Service Restarted'
}

get-service 'ServiceName1', 'SercieName2' | ? { $_.Status -eq 'Stopped'  } | % {
  $_ | start-service
  sleep 1
  $result = if (($_ | get-service).Status -eq "Running") {"success"} else {"failure"}
  Send-MailMesssage @MailParm -Body "Service $($_,Name) has been restarted with $result"
}

Open in new window

This works with an array of service names, as shown.
0
 

Author Closing Comment

by:Mickail
ID: 40540255
This is spot on.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

The article will show you how you can maintain a simple logfile of all Startup and Shutdown events on Windows servers and desktops with PowerShell. The script can be easily adapted into doing more like gracefully silencing/updating your monitoring s…
Create and license users in Office 365 in bulk based on a CSV file. A step-by-step guide with PowerShell script examples.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now