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,549 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

Are your AD admin tools letting you down?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
A procedure for exporting installed hotfix details of remote computers using powershell
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

856 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