Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
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
Medium Priority
?
4,261 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 71

Accepted Solution

by:
Qlemo earned 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

688 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