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,639 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 69

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

685 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