0

I am trying to upload the appx to hockey app using PowerShell script. When I run the PowerShell script getting below error:

Invoke-RestMethod : The underlying connection was closed: Could not establish 
  trust relationship for the SSL/TLS secure channel.

  At C:\PROG\WorkWise-Windows\UploadToHokeyScript\HockeyApp_HPWorkWiseTrayUploadS
  cript.ps1:20 char:13
  + $response = Invoke-RestMethod -Method POST -Uri $create_url -Header @ ...
  +             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:Htt 
     pWebRequest) [Invoke-RestMethod], WebException
      + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe 
     ll.Commands.InvokeRestMethodCommand

Help is appreciated.

Ankush Butole
  • 151
  • 13
  • 1
    Possible duplicate of [Powershell v3 Invoke-WebRequest HTTPS error](https://stackoverflow.com/questions/11696944/powershell-v3-invoke-webrequest-https-error) – TessellatingHeckler Aug 18 '17 at 06:59

1 Answers1

0

Add below step on top of Invoke-restMethod -Uri

add-type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
        ServicePoint srvPoint, X509Certificate certificate,
        WebRequest request, int certificateProblem) {
        return true;
    }
}
"@

[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy 
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12