Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4659
  • Last Modified:

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

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
Mickail
Asked:
Mickail
1 Solution
 
QlemoBatchelor, Developer and EE Topic AdvisorCommented:
$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
 
MickailAuthor Commented:
This is spot on.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now