title: Powershell Invoke-RestMethod certificate validation
body: <p>I have been using a script that has been working for a year without issue, making a call to Invoke-RestMethod to a secure (https) site, which is now failing.  After a much testing I found that I can make the call fail consistently and reproducible for <strong>any</strong> secure site request but I don't know why.  The following code fails.</p>
  
  <pre><code>[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  Invoke-RestMethod -Uri https://blogs.msdn.com/powershell/rss.aspx | Format-Table -Property Title, pubDate
  </code></pre>
  
  <p>The error produced is the following:</p>
  
  <blockquote>
    <p>Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
    At line:1 char:1
    + Invoke-RestMethod -Uri <a href="https://blogs.msdn.com/powershell/rss.aspx" rel="nofollow noreferrer">https://blogs.msdn.com/powershell/rss.aspx</a> | Format-Table ...
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
          + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
          + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand</p>
  </blockquote>
  
  <p>I found that if I <strong>include</strong></p>
  
  <pre><code>[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  </code></pre>
  
  <p>the above line, I get the previously shown error.  The above behavior and error is actually the <strong>opposite</strong> of what should occur.  Previously, I could not make the https request without assigning the ServerCertificateValidationCallback to be true.</p>
  
  <p>I have tried this from multiple computers, under different Windows user profiles, launching PowerShell using administrative privileges but I find adding the above line enables me to reproduce the problem.  In order to make it work, I must close PowerShell, reopen it and remove the ServerCertificateValidationCallback line.  If I add the line to the code, the error returns.  </p>
  
  <p>The last time I ran my code was two weeks ago, so that is as narrowly as I can pinpoint the timeframe.  Any ideas on why this is now failing?</p>
  
  <p>Note this is <strong>not</strong> the site I was originally having a problem with however, the issue I am facing can be reproduced with the above code.</p>