If you’ve been working with New-WebServiceProxy in PowerShell and have insecure (hopefully) internal sites that you are working with, you’ve undoubtedly seen the following message:
New-WebServiceProxy : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel. At line:1 char:20 + New-WebServiceProxy <<<< -Uri https://[SERVERNAME]:[PORT]/[URLtoWSDL] + CategoryInfo : ObjectNotFound: (https://[SERVERNAME]:[PORT]/[URLtoWSDL]:Uri) [New-WebServiceProxy], WebException + FullyQualifiedErrorId : WebException,Microsoft.PowerShell.Commands.NewWebServiceProxy
I’ve browsed around the Internet for hours and hours to find the fix for this, and then I stumbled across this page, hosted by PoSH Pete: New-WebServiceProxy and SSL.
It all boils down to a quick simple fix by adding one line before you create the Web Service Proxy.
[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
Thank you! Thank you! I’m not sure what changed in my environment, but my New-WebServiceProxy was working, then it stopped. This post is a lifesaver!
This is an old posting, but is still relevant these days for many people.
Thank you for your post. I had the same issue. You solve my problem.
Cool. Its working 🙂
This fixed an issue where the code was working a month ago, but today, failed. Thank You
Thanks, you saved me a ton of headache with this simple fix!