none
Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure channel. RRS feed

  • Question

  • I Guys,


    I am using one script . it was working fine before 6 days but now giving error. I am using the Labtech software to monitor machines. when monito fails then this script runs on machine and send the result to opsGenis email. then ops genie sends the alert on phone via SMS or voice call. 

    this is the error when script run on server . FYI, server is exchange server.

    Invoke-RestMethod : The request was aborted: Could not create SSL/TLS secure 
    
    channel.
    
    At C:\Windows\system32\config\systemprofile\AppData\Local\9e1cd5b9f46d4e17b9179
    
    fbe197f1909.ps1:36 char:11
    
    + $result = Invoke-RestMethod -Method "Post" -Uri $uri -Headers $headers -Body 
    
    $bo ...
    
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ~~~
    
    + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:Htt 
    
    pWebRequest) [Invoke-RestMethod], WebException
    
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShe 
    
    ll.Commands.InvokeRestMethodCommand
    

    This is the script :-

    param (
    
      [string]$eu = "False",
    
      [string]$apiKey = "apiKey",
    
      [string]$status = "status",
    
      [string]$clientname = "client",
    
      [string]$computername = "computer",
    
      [string]$locationname = "location",
    
      [string]$fieldname = "field",
    
      [string]$result = "result",
    
      [string]$when = "when",
    
      [string]$contactName = "contact",
    
      [string]$monitorName = "monitor"
    
    )
    
    
      if($eu -eq "True") {
    
      $uri = "https://api.eu.opsgenie.com/v1/json/integrations/webhooks/connectwiseautomate?apiKey=" + $apiKey;
    
    }
    
    else {
    
      $uri = "https://api.opsgenie.com/v1/json/integrations/webhooks/connectwiseautomate?apiKey=" + $apiKey;
    
    }
    
    
    $body = ConvertTo-Json @{
    
      status = $status
    
      clientName = $clientname
    
      computerName = $computername
    
      locationName = $locationname
    
      fieldName = $fieldname
    
      result = $result
    
      when = $when
    
      contactName = $contactName
    
      monitorName = $monitorName
    
    }
    
    $headers = [Hashtable] @{
    
        Type = 'application/json'
    
    };
    
    $result = Invoke-RestMethod -Method "Post" -Uri $uri -Headers $headers -Body $body -ContentType 'application/json'
    
    Write-Output $result

    Thanks

    Saturday, March 23, 2019 3:25 AM

Answers

  • I ran a ssl server test against api.opsgenie.com from ssllabs.com and noticed the certificate is valid from 18 Mar 2019 which suggests they recently renewed the certificate. I also notice they only support TLS 1.2. My guess is they removed support for older security protocols around the time they installed the new certificate.

    Is Tls12 listed if you run [Net.ServicePointManager]::SecurityProtocol in PowerShell?

    You could force PowerShell to use Tls12 by running the following before you run Invoke-RestMethod.

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    Saturday, March 23, 2019 9:15 PM

All replies

  • Sorry but this is not a scripting issue.  You have to find out what was change in your network or the target system.  We cannot help you with this.

    If this is critical then open a ticket with MS Support.


    \_(ツ)_/

    Saturday, March 23, 2019 4:04 AM
  • I ran a ssl server test against api.opsgenie.com from ssllabs.com and noticed the certificate is valid from 18 Mar 2019 which suggests they recently renewed the certificate. I also notice they only support TLS 1.2. My guess is they removed support for older security protocols around the time they installed the new certificate.

    Is Tls12 listed if you run [Net.ServicePointManager]::SecurityProtocol in PowerShell?

    You could force PowerShell to use Tls12 by running the following before you run Invoke-RestMethod.

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

    Saturday, March 23, 2019 9:15 PM
  • Thanks leif.  I add [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 this line in center and it is working now.

    Sunday, March 24, 2019 5:04 PM