title: Powershell web request without throwing exception on 4xx/5xx
body: <p>I'm writing a powershell script that needs to make a web request and inspect the status code of the response.</p>
  
  <p>I have tried writing this:</p>
  
  <pre><code>$client = new-object system.net.webclient
  
  $response = $client.DownloadData($url)
  </code></pre>
  
  <p>as well as this:</p>
  
  <pre><code>$response = Invoke-WebRequest $url
  </code></pre>
  
  <p>but whenever the web page has a status code that's not a success status code, PowerShell goes ahead and throws an exception instead of giving me the actual response object.</p>
  
  <p>How can I get the status code of the page even when it fails to load?</p>