title: Is there a way to end Invoke-WebRequest when response time (not name resolution) longer than x?
body: <p>I want to run a script that checks website response time (not DNS name resolution time) throws an exception when response time is longer than e.g. 60 seconds. </p>
  
  <p>I use <code>httpstat.us/200?sleep=70000</code> (i.e. wait for 70 seconds) for testing, but can't find a solution, since <code>-TimeoutSec</code> is only checking name resolution time. I don't understand how creating a job or a timer could help in this circumstance.  I tried below code in another forum, which (of course) doesn't work, since it waits for the command to finish. How can I break/interrupt it after 60 seconds?</p>
  
  <pre class="lang-bsh prettyprint-override"><code>$url = 'httpstat.us/200?sleep=70000'
  $Duration = 60
  
  $TimeOut = New-TimeSpan -Seconds $Duration
  $Sw = [Diagnostics.Stopwatch]::StartNew()
  while ($Sw.Elapsed -lt $TimeOut) {
      try {
          Invoke-WebRequest -Uri $url
      } catch [System.Exception] {
          # Writing the exception in the console
          Write-Host $_.Exception
          exit;
      }
  } #EndOf while ($Sw.Elapsed -lt $TimeOut)
  </code></pre>