title: Catch errors from New-WebServiceProxy in PowerShell
body: <p>I would like to use New-WebServiceProxy in my PowerShell script. I need more than one service to be up and running before continuing, but for some reason I cannot programatically catch the WebException and quit the script at this point.</p>
  <p>Example:</p>
  <pre><code>$ws_uri = &quot;http://localhost/no_service&quot;
  $status = &quot;not run&quot;
  
  try {     
      $proxy = New-WebServiceProxy -uri $ws_uri -UseDefaultCredential 1
      $status = &quot;The service is up and running.&quot;
  } catch {
      $status = &quot;The service is down&quot;    
  }
  
  Write-Host Status of first web service
  Write-Host $status
  
  
  $ws_uri = &quot;http://www.soapclient.com/xml/SQLDataSoap.WSDL&quot;
  try {     
      $proxy = New-WebServiceProxy -uri $ws_uri
      $status = &quot;The service is up and running.&quot;
  } catch {
      $status = &quot;The service is down&quot;    
  }
  
  Write-Host Status of second web service
  Write-Host $status
  </code></pre>
  <p>Instead of entering the exception part, I only get an error in the PowerShell window like this:</p>
  <pre><code>PS C:\test&gt; .\test.ps1
  New-WebServiceProxy : The request failed with HTTP status 404: Not Found.
  At C:\test\test.ps1:5 char:14
  +     $proxy = New-WebServiceProxy -uri $ws_uri -UseDefaultCredential 1
  +              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : ObjectNotFound: (http://localhost/no_service:Uri) [New-WebServiceProxy], WebException
      + FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
  Status of first web service
  The service is up and running.
  Status of second web service
  The service is up and running.
  </code></pre>
  <p>I tried to be more specific with the exception using [System.Net.WebException], but that does not change anything.</p>