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
321 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
1 Comment
 
LVL 78

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

How to sign a powershell script so you can prevent tampering, and only allow users to run authorised Powershell scripts
This article will help you understand what HashTables are and how to use them in PowerShell.
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…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now