title: could not create SSL/TLS secure channel invoke-webrequest task scheduler with service account
body: <p>I have found plenty of resource on the first part of my question, specifically though I'm looking for solutions for it being used with task scheduler / service account</p>
  
  <p>I have a PowerShell script which sucks up some logs and forwards them to an endpoint. This is run via a scheduled task. The account that does the forwarding has a valid certificate to be able to send to the end point</p>
  
  <p>I have tested the PowerShell script using my certificate and it works as intended. I have also tested that the service accounts certificate is valid but from being run as myself as opposed to the service account. I am unable to test it from the service account as it does not have any logon rights</p>
  
  <p>I have updated the <code>[net.servicepointmanager]::securityprotocol</code> as stated <a href="https://stackoverflow.com/questions/41618766/powershell-invoke-webrequest-fails-with-ssl-tls-secure-channel">here</a>.</p>
  
  <p>I believe the error <code>Could not create ssl/tls secure channel</code> is the correct error but I believe the cause is not the common one found by googling this</p>
  
  <p>What else should I test to see what's going on here?
  PSVersion 5.1, .Net 4.5</p>
  
  <p>As requested here a bunch of the code I am using to gain the certificate of the service account</p>
  
  <pre><code>[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  $subject = "account"
  $certs = Get-ChildItem("certs:\") -recurce | Where-object {($_.Subject -like "*$subject*" -and $_.HasPrivateKey -eq $true)}
  $cert = $certs | Sort-object $_."Not Before" | select-object -first 1
  $file = gci(D:\Temp)
  $contentType = "application/json"
  
  $request = Invoke-Webrequest -uri "mydestination" -Certificate $cert -Method Post -infile $file.Fullname -contentType $contentType
  </code></pre>