Friday, July 25, 2014

Ignore SSL Certificate Check in PowerShell

Sometimes we might be using self signed or different domain SSL certificate for staging or QA specific websites. In Windows PowerShell, when HttpRequest is used to make requests to such websites, below error is thrown

The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.

This error means that the server certificate validation failed. If we want to ignore SSL validation check in PowerShell, we must write a call back for server certificate validation. To do this, just add below line of code before actual the HttpRequest call:

[System.Net.ServicePointManager]::ServerCertificateValidationCallback = { $true }

Above line will always return true which means that SSL certificate validation was successful.

2 comments:

  1. Thanks for this. I was looking for a way to replace older code that used [System.Net.ServicePointManager]::CertificatePolicy=

    ReplyDelete