TIL how to ignore SSL cert verification in Powershell
In Powershell 5.1, there is no flag to easily ignore SSL/TLS verification in curl
or Invoke-WebRequest
. The following is a workaround:
add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
public bool CheckValidationResult(
ServicePoint srvPoint, X509Certificate certificate,
WebRequest request, int certificateProblem) {
return true;
}
}
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy
Invoke-WebRequest -Uri "https://api.example.com"
In Powershell >7, we can use the -SkipCertificateCheck
flag.