title: Automatically restart computer when internet connection is lost
body: <p>I have some trouble to do a script for Windows&nbsp;10 that will check my internet connection every 2 minutes and restart the computer if it doesn’t find any connection.</p>
  
  <p>I tried with PowerShell:</p>
  
  <pre><code>mainLoop() 
  sleep 120
  {
      if (!(Test-Connection 8.8.8.8 -Quiet)) {
          #Write-Host "Not connected"
          Restart-Computer
      } else {
          mainLoop()
      }
  }
  </code></pre>
  
  <p>Do you have some advice to make it works?</p>