T
T
Today I learned
Search…
Set Powershell to skip SSL certificate checks

NOTE: This is NOT a recommended practice! You should have valid certificates and CA Servers!

If you are trying to query a web site and you have invalid SSL certificates, Powershell is by default very strict on what it accepts. You will often end up with errors like:
1
Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
Copied!
or
1
Invoke-WebRequest : The request was aborted: Could not create SSL/TLS secure channel.
Copied!
When you try to use Invoke-WebRequest or Invoke-RestMethod on a web URL with old or insecure certificates or CAs. Example:
1
PS C:\Users\CorrM1> Invoke-WebRequest -Uri https://badwebsite.with.crap.certs:1943/application/service
Copied!
To get around this, try running the script fragment below before you make your remote calls.
This performs bypasses for the certificate issues.
1
add-type @"
2
using System.Net;
3
using System.Security.Cryptography.X509Certificates;
4
public class TrustAllCertsPolicy : ICertificatePolicy {
5
public bool CheckValidationResult(
6
ServicePoint srvPoint, X509Certificate certificate,
7
WebRequest request, int certificateProblem) {
8
return true;
9
}
10
}
11
"@
12
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Copied!
Copy link