title: PowerShell: How can I determine if Invoke-WebRequest has timed out?
body: <p>I need to produce some output when Invoke-WebRequest exceeds the time limit set by the -TimeoutSec parameter. How can I build an If condition that runs when this is the case?</p>
  <p>In other words; what goes in place of ????? in the example below?:</p>
  <pre><code>Try {
    Invoke-RestMethod -Uri $Uri -contentType &quot;application/json&quot;
     -Method Post -Headers $Headers -Body $Body -TimeoutSec 8
  }
  Catch {
   If (?????) {
      Write-Host &quot;the request timed out...&quot;
    }
  }
  </code></pre>