This is one of the most common problems when you encounter an unhandled exception in powershell. You must use -ErrorAction Stop
in the New-WebServiceProxy
command
try { $myService = New-WebServiceProxy -Uri "http://localhost/someservice.svc" -ErrorAction Stop } catch [System.Net.WebException]{ Write-Log ([string]::Format("Error : {0}", $_.Exception.Message)) }
Updated: To catch the Http exception, enable [System.Net.WebException]
as pointed out by Keith Hill in the comment below.
Mitul source share