Question
Is there a way I can call Invoke-WebRequest
and for example expect a given public key of the certificate to validate that I trust the connection?
If not, is there another way to invoke the webrequest and only trust the webpage without trusting the issuer or ignoring the certificate check?
Problem
I want to load an webpage with Invoke-WebRequest
. I try to connect to the Webpage over https and the server offers an self-signed certificate.
Since I dont't have the Issuer-Certificate in my certificate-store Invoke-WebRequest
will throw the error:
Invoke-WebRequest : The remote certificate is invalid according to the validation procedure.
Known workarounds
- Using the
-SkipCertificateCheck
-Switch added in Powershell v6.0.0 ref - Adding a new Certificatepolicy to trust all Certificates ref
- Trusting the Issuer-Certificate
What I tried but didn't work out
- Adding the Webpage-Certificate to the certificate-store without trusting the Issuer-Certificate
- Adding the Webpage-Certificate to the certificate-store and using the
-Certificate
-Parameter ofInvoke-WebRequest
to specify this certificate
PS: Since this problem appears in both Powershell <5 and Powershell Core, I am tagging both.