Email alert using PowerShell when a windows service failed

You can use Windows PowerShell to send you an email notification when a windows service failed.  Here are the steps:
1. Open Windows Services by doing start –> Run –> Services.msc

2. Right Click on the Service and go to Properties and chose Recovery tab

3. Select Run a Program

image
In the Run Program below type
C:\Windows\System32\Windows PowerShell\v1.0\PowerShell.exe
In the Command line type the following
&  "Send-Mail Message –To visionabove@gmail.com -Subject \"Service Failed\" -Body \"Please Action\" -SmtpServer YOURSMTPSERVER -From visionabove@gmail.com"

Click on Apply and OK. 

Go to Task Manager and end the Process.

You should receive an email

Comments

  1. I tried it and did not work.

    & "Send-Mail Message –To jyoukhanis@aap.org -Subject \"Service Failed\" -Body \"Please Action\" -SmtpServer mail.aap.org-From sqlserver@aap.org" Please help.

    ReplyDelete
  2. I tried it and did not work.

    & "Send-Mail Message –To jyoukhanis@aap.org -Subject \"Service Failed\" -Body \"Please Action\" -SmtpServer mail.aap.org-From sqlserver@aap.org" Please help.

    ReplyDelete
    Replies
    1. James Youkhanis
      Can you run powershell in administrator mode and there should be a space before the -From

      Delete
  3. I had issues with this method to but after a lot of testing was able to get the following method working on my Windows 2016 server.

    1. Set the service recovery to restart on First and Second failures.
    2. Set subsequent failures to Run a Program.
    3. Set the program to run to be:
    C:\Windows\System32\WindowsPowerShell\v1.0\PowerShell.exe -Command "Send-MailMessage -To myteam@test.com -From server@test.com -Subject \"This Service Failed\" -Body \"The Service has failed and there may be issues with this. Please log into the server and troubleshoot the service.\" -Priority High -SmtpServer smtp.test.com
    4. Set Reset fail count after to be 1 day and Restart service after 1 minute

    ReplyDelete
  4. Makasih ya infonya bermanfaat.

    Boleh dong kunjungan balik ke blog saya,
    ditunggu di sini ya : https://slashdot.org/submission/13323430/pt-agres-info-teknologi---toko-komputer-online

    ReplyDelete

Post a Comment

Thank you for your comments

Popular Posts