Created
January 13, 2017 22:07
-
-
Save vendettamit/6b1fe7d0e4c45f39cb596526af7bbcfd to your computer and use it in GitHub Desktop.
Check windows service status and email if stopped using power shell script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$client = "Test" | |
$service="" | |
$EmailBody = "" | |
$EmailSubject = "" | |
$SMTPServer = "relay2" | |
$PCName = $env:COMPUTERNAME | |
$EmailFrom = "$client <[email protected]>" | |
$EmailTo = "[email protected]" | |
# Check diary sender service status | |
$service="CourtAlert Diary Sender" | |
$result = Get-Service | Where-Object {$_.status -eq "stopped"} | findstr /c:"$($service)" | |
if(![string]::IsNullOrEmpty($result)) | |
{ | |
$EmailBody= "The '$($service)' service has stopped on $($PCName)." | |
$EmailSubject = "$($service) important alert" | |
Write-host "Sending Email alert for $($service)" | |
Write-Host $EmailBody | |
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer -Priority High | |
} | |
$service="CourtAlert Mail Relay" | |
$result = Get-Service | Where-Object {$_.status -eq "stopped"} | findstr /c:"$($service)" | |
if(![string]::IsNullOrEmpty($result)) | |
{ | |
$EmailBody= "The '$($service)' service has stopped on $($PCName)." | |
$EmailSubject = "$($service) important alert" | |
Write-host "Sending Email alert for $($service)" | |
Write-Host $EmailBody | |
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer -Priority High | |
} | |
$service="CourtAlert ECF" | |
$result = Get-Service | Where-Object {$_.status -eq "stopped"} | findstr /c:"$($service)" | |
if(![string]::IsNullOrEmpty($result)) | |
{ | |
$EmailBody= "The '$($service)' service has stopped on $($PCName)." | |
$EmailSubject = "$($service) important alert" | |
Write-host "Sending Email alert for $($service)" | |
Write-Host $EmailBody | |
Send-MailMessage -From $EmailFrom -To $EmailTo -Subject $EmailSubject -body $EmailBody -SmtpServer $SMTPServer -Priority High | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment