New-WebServiceProxy & SSL

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}

6 thoughts on “New-WebServiceProxy & SSL”

  1. 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!

    Reply

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.