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
322 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Citrix XenApp, Internet Explorer 11 set to Enterprise Mode and using central hosted sites.xml file.
"Migrate" an SMTP relay receive connector to a new server using info from an old server.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
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…

920 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

16 Experts available now in Live!

Get 1:1 Help Now