A script to monitor servers, Ping Test, with email notification

The Script runs against a list of Servers and notifies the user if the servers are down.

4.3 Star
12,938 times
Add to favorites
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question

  • cannot send email
    1 Posts | Last post December 18, 2017
    • After it detected that host is not reachable it prompt to enter subject then comes the error.
      Supply values for the following parameters:
      Subject: sin-lt-052
      Send-MailMessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.1 Client was not authenticated
      At C:\Users\israelm\Desktop\Untitled1.ps1:70 char:17
      +                 Send-MailMessage -Body "$body" -to $notificationto -from $notifi ...
      +                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
          + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
      -Subject : The term '-Subject' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
      At C:\Users\israelm\Desktop\Untitled1.ps1:71 char:18
      +                  -Subject "Host $_ is down" -SmtpServer $smtpserver
      +                  ~~~~~~~~
          + CategoryInfo          : ObjectNotFound: (-Subject:String) [], CommandNotFoundException
          + FullyQualifiedErrorId : CommandNotFoundException
  • Email credentials
    1 Posts | Last post November 02, 2017
    • Little new to PS. so my apologies....
      How do you add email credentials to this?  My email server requires username and password to forward emails.
  • works great, 2 points
    1 Posts | Last post November 02, 2017
    • 1. missing code:
       $Now = Get-date
      between lines 67 and 68. without it no time is generated in emails.
      2. emailing multiple recipients. I hacked it by duplicating the "Send-MailMessage" code. worked fine, but probably a much neater way to do this.
      Very powerful script for its size. thanks :)   
  • Could I get average MS to display?
    1 Posts | Last post October 31, 2017
    • I would like to be able to have the PowerShell script do this: run a ping test to a IP address-(input variable) for count-(input variable), and size-(input variable) then would *IF* Average-(input variable) is Greater Than-(input variable) *AND/OR/NOT* Lost-(input variable) is Greater Than-(input variable) *THEN* email-(input mailto:) Subject:-(input text), Body: Average, Loss, Message-(input text)?
      What changes could be made to satisfy this particular problem?
      Thank you,
  • Loop Timeout - Can it be set?
    1 Posts | Last post September 19, 2017
    • Hi Ben,
      Thank you so much for the script. It has helped a lot.
      Can you change the timeout for the loop?
      I want the Loop to run for only 5 minutes.
      I created a Scheduled Task on my Server to Run every hour, to execute the script.
      Matthew (Cape Town)
  • Hello Benn
    1 Posts | Last post July 31, 2017
    • Hello Ben,
      Thank you so much for the script.
      Can we make it get even working servers count via email. If so could you please help me in updating the script.
      Thank you again for a wonderful script 
  • Default settings runtime
    3 Posts | Last post June 14, 2017
    • Hello Ben,
      THanks for this very useful script.
      I was wondering, given the default values SleepTimeout=45, MaxOutageCount=10 and EmailTimeOut=30
      Does this mean the running it as such, it would run/loop for 45*10 Seconds before stopping and then send an email out 30seconds after last 10th run/loop is done?
      My ideal schedule would be to run every 6hrs and then email only if theres an unavailable host during a loop and then continue with its next scheduled run. 
      So, would this work as such? thanks
      $OutageHosts = $Null
      # specify the time you want email notifications resent for hosts that are down
      $EmailTimeOut = 14400
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = 21600
      # specify the maximum hosts that can be down before the script is aborted
      $MaxOutageCount = 1
    • Hello again,
      I think i worded the question wrongly. I meant to ask what values would make this run for an hour and then just stop. Then run again when the scheduler starts it again and so on and so forth?
      Currently, it seems it just keeps running and pauses and runs again. I'd like it to stop completely and pickup again later.
    • Hello The SOlution that works for me is to set the values as such:
      # specify the time you want email notifications resent for hosts that are down
      $EmailTimeOut = 10
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = 10
      # specify the maximum hosts that can be down before the script is aborted
      $MaxOutageCount = 0
      Task Scheduler then runs every 6hrs to activate a batch script that initiates the powershell.
      Thanks Ben.
  • Hey Ben, this is fantastic! Thank you!
    4 Posts | Last post May 05, 2017
    • I've got this working just fine now after tweaking a few antivirus settings (until then I was getting an 'unable to connect to the remote server' error.)
      It's almost perfect, but I'm wondering if you can advise how to tweak it to do the following:
      1) I only want to send the email after the ping cycle has completed three times and is still unsuccessful.  So for example, if I want the sleep period to be 24 hours (resulting in the script effectively running once a day), I only want it to send an email if it fails to ping for 3 continuous days.
      2) Is there an easy way to prevent it from sending an email every day until connectivity has been restored?  For our purposes, it's unnecessary to notify an individual more than once.
      I'd appreciate any ideas you have.  I have a little experience with other coding languages but PowerShell is still pretty foreign to me.
      Thanks again for this wonderful tool!
    • The settings are there, it already pings 4 time over two cycles before it sends an email
      # specify the time you want email notifications resent for hosts that are down 
      $EmailTimeOut = (60 * 24)
    • Thanks, Ben!
      So for example if I want it to send an email every three days and cycle through the host list once a day, I'd modify the parameters to:
      $EmailTimeOut = (60 * 24 * 3)
      # specify the time you want to cycle through your host lists.
      $SleepTimeOut = (60 * 24)
    • The script is on a loop and it checks to send an email based on the $EmailTimeOut value, which is in seconds.
      So if you want to send an email every minute (60 seconds) $EmailTimeOut = 60
      If you want to send an email every hour $EmailTimeOut = (60 * 60)
      If you want to send an email every day $EmailTimeOut = (60 * 60 * 24)
      There is not much point in not doing a continuous loop, you may as well see the continuous update, then just decide when you want alerts sent if machines go down.
  • Not able to get ping status even if the system is up for some of the servers
    2 Posts | Last post April 05, 2017
    • Hi Ben, Thanks for a wonderful script. I have noticed even if my servers are up and able to do a lookup. script is not able to ping many of the computers in the list. I need your help in make the ping for some more pings and need a html output file so as to setup a status monitor which shows green is server up and red in server down.
      Thanks and regards,
    • by default ICMP is not enabled on servers due to the firewall.
      You may want to use Test-NetConnection or Test-WsMan instead, since they will respond by default.
      As far as the html report goes, one step at a time try to get a functional solution first with the responses.
  • Failed Host Back Online notification?
    2 Posts | Last post March 22, 2017
    • Hi Ben! GREAT script! thanks so much! I got it to work perfectly on my environment except one thing.
      I've tried few things but all I can get it to work is to email me every min once a host goes down. 
      Could you please help with the code to email me when a failed host is back up?
    • There is a parameter for that
      $EmailTimeOut = 30 
      Basically after this amount of time the host will be removed from the known hosts that are down, if the host is still down, then it will cause a new notification to be sent.
      So basically change that to 5 and you will get emailed every 5 minutes until the host is back online.
1 - 10 of 21 Items