title: Trusting self-signed certificate in Invoke-WebRequest call
body: <h2>Question</h2>
  
  <p>Is there a way I can call <code>Invoke-WebRequest</code> and for example expect a given public key of the certificate to validate that I trust the connection?</p>
  
  <p>If not, is there another way to invoke the webrequest and only trust the webpage without trusting the issuer or ignoring the certificate check?</p>
  
  <h2>Problem</h2>
  
  <p>I want to load an webpage with <code>Invoke-WebRequest</code>. I try to connect to the Webpage over https and the server offers an self-signed certificate.</p>
  
  <p>Since I dont't have the Issuer-Certificate in my certificate-store <code>Invoke-WebRequest</code> will throw the error:</p>
  
  <blockquote>
    <blockquote>
      <p>Invoke-WebRequest : The remote certificate is invalid according to the validation procedure.</p>
    </blockquote>
  </blockquote>
  
  <h2>Known workarounds</h2>
  
  <ol>
  <li>Using the <code>-SkipCertificateCheck</code>-Switch added in Powershell v6.0.0 <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-webrequest?view=powershell-6#parameters" rel="noreferrer">ref</a></li>
  <li>Adding a new Certificatepolicy to trust all Certificates <a href="https://stackoverflow.com/a/15841856/6404133">ref</a> </li>
  <li>Trusting the Issuer-Certificate</li>
  </ol>
  
  <h2>What I tried but didn't work out</h2>
  
  <ol>
  <li>Adding the Webpage-Certificate to the certificate-store without trusting the Issuer-Certificate</li>
  <li>Adding the Webpage-Certificate to the certificate-store and using the <code>-Certificate</code>-Parameter of <code>Invoke-WebRequest</code> to specify this certificate</li>
  </ol>
  
  <p><em>PS: Since this problem appears in both Powershell &lt;5 and Powershell Core, I am tagging both.</em></p>