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
329 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 81

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
In previous parts of this Nano Server deployment series, we learned how to create, deploy and configure Nano Server as a Hyper-V host. In this part, we will look for a clustering option. We will create a Hyper-V cluster of 3 Nano Server host nodes w…
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…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…

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