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:
Invoke-WebRequest : The underlying connection was closed: Could not establish trust relationship for the SSL/TLS secure channel.
For the work around, try to run the script below before sending the invoke commands. This will ignore the ssl certificate error validation in the current PowerShell Session.
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