Solved

Looking for a script/powershell to go to a specified number of servers to check if specific services are running and email if not started.

Posted on 2013-06-04
1
325 Views
Last Modified: 2013-08-29
I'm currently looking for a way to run a script/powershell to check a number of windows 2003 servers to see if a specific service is started or not, and return if the service is not started an email to administrators. This would greatly reduced the amount of time it takes to troubleshoot some of my processes
0
Comment
Question by:cgooden01
[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
1 Comment
 
LVL 80

Accepted Solution

by:
David Johnson, CD, MVP earned 300 total points
ID: 39220788
$emailto = "abc@example.com "
$subject = "Stopped Services Report"
$servers = get-content c:\servers.txt
$services = get-content c:\services.txt

foreach ($server in $servers) {
    if (Test-Connection $servers -Count 1 -ErrorAction SilentlyContinue) {
        foreach($service in $services) {
               $status = Get-Service -Name $service -ComputerName $servers -ErrorAction SilentlyContinue
               if ($status.status -eq "Stopped") {
                        $statusmsg = $server + " Service:" + $service + "Is Stopped"
                        Send-MailMessage -To $Emailto -Subject $subject  -From "ServerStatusEmailer@XXXXXXXX" -SmtpServer "XXXXXX" `
                            -Body  $statusmsg -BodyAsHtml
                        }
               }
    }
}

Open in new window

0

Featured Post

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

735 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