Friday, May 13, 2016

Simple powershell script to report Internet unavailability

A simple script that check the state of internet connectivity and output time and date of unavailability to screen.


$ping = new-object System.Net.Networkinformation.Ping

While($true)
{
   $result = $ping.send("8.8.8.8")
   sleep 10
   $result1 = $ping.send("8.8.4.4")
   sleep 10

   if(($result.status -ne "Success") -and ($result1.status -ne "Success"))
   {
      $date = date
      $message = "Internet unavailable: " + $date
      echo $message
    }
    sleep 60
}