title: PowerShell HTTPS GET using client certificate from certstore
body: <p>I'm trying find easy way how check web content via HTTPS with using client certificate.
  I have VBScript where is defined Client certificate, skipped Server certificate and defined what I'm searching (string "running"). My point is rewrite script to PowerShell.</p>
  
  <p>Here is VBScode:</p>
  
  <pre><code>device = "10.10.10.10"
  link = "5001/test"
  Set Http = CreateObject("WinHttp.WinHttpRequest.5.1")
  Http.SetClientCertificate "LOCAL_MACHINE\MY\test"
  Http.Option(4) = 256 + 512 + 4096 + 8192 
  Http.Open "GET", "https://" &amp; device &amp; ":" &amp; link, false
  Http.Send
  output = Http.ResponseText
  If InStr(1,output,"running") Then
  wscript.echo "OK"
  Else
  wscript.echo "Error"
  End If
  Set Http = Nothing
  </code></pre>
  
  <p>Here is Powershell syntax to get HTTP web content (but not https):</p>
  
  <pre><code>$page = (New-Object System.Net.WebClient).DownloadString("http://10.10.10.10:5001/test")
  "$page"
  </code></pre>
  
  <p>Here is Powershell syntax to get HTTPS contetn using .CRT file (but not from CERTSTORE)</p>
  
  <pre><code>[System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  $cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]::CreateFromCertFile("C:\Cert\test.crt")
  $url = "https://10.10.10.10:5001/test"
  $web = [System.Net.WebRequest]::Create($url)
  $web.ClientCertificates.Add($Cert)
  </code></pre>
  
  <p>Here is my latest try to get web contetn. No success.</p>
  
  <pre><code>#ignore untrusted certificate
  [System.Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}
  #load my client certificate defined by thumbprint
  $cert = Get-Childitem cert:\LocalMachine\My\5AA55B7B8D99
  #get web contetn
  $web = [System.Net.WebRequest]::Create($url)
  #use my client certificate
  $web.ClientCertificates.Add($Cert)
  </code></pre>
  
  <p>Any ideas ?
  Best regards</p>