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
(19)
13,970 times
Add to favorites
Servers
7/16/2014
E-mail Twitter del.icio.us Digg Facebook
Sign in to ask a question


  • Loop Timeout - Can it be set?
    2 Posts | Last post March 20, 2018
    • Hi Ben,
      
      Thank you so much for the script. It has helped a lot.
      
      Question: 
      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.
      
      
      Regards,
      Matthew (Cape Town)
      
      
      
    • Since it's in a Do While loop it will run forever.
      
      However you can modify the While statement.
      
      while ($Exit -ne $True) 
      
      Perhaps just set a variable at the beginning, that has the starttime in it. then once the start time - the current time is greater than 120 seconds, return $False. you can use new-timespan to calculate the timespan.
  • I am getting error here as no SMTP server was specified
    2 Posts | Last post March 20, 2018
    • Send-MailMessage -Body "$body" -to $notificationto -from $notificationfrom ` 
                        -Subject "Host $_ is down" -SmtpServer $smtpserver 
      
      
      getting error in these two lines
      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
    • I recommend to download the script to get the correct formatting.
      
      Since you copied and pasted it you have a space after the `
  • getting error at line 53
    3 Posts | Last post January 30, 2018
    • 	Missing expression after unary operator '-'.
      At C:\Users\20555\Desktop\test.ps1:53 char:20
      +                   - <<<< Subject "Host $_ is down" -SmtpServer $smtp
          + CategoryInfo          : ParserError: (-:String) [], ParseExcepti
          + FullyQualifiedErrorId : MissingExpressionAfterOperator
      
      line 53:-Subject "Host $_ is down" -SmtpServer $smtpserver 
      
      
      
    • did you download the script or copy and paste?
    • I recommend to download to get the correct formatting.
      
      you have a space after the `
  • cannot send email
    3 Posts | Last post January 30, 2018
    • 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
    • did you download the script or copy and paste?
    • I recommend to download to get the correct formatting.
      
      you have a space after the `
  • Email credentials
    2 Posts | Last post January 30, 2018
    • 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.
      
      Thanks
      
      Blake
    • help Send-MailMessage -Examples
  • 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,
  • 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.
      thanks.
    • 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)
      
      Right?
    • 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.
1 - 10 of 23 Items