ITPAM Run Script Invoke-RestMethod returns: The underlying connection was closed
search cancel

ITPAM Run Script Invoke-RestMethod returns: The underlying connection was closed

book

Article ID: 222150

calendar_today

Updated On:

Products

CA Process Automation Base

Issue/Introduction

While using the "Run Script" operator to execute Invoke-RestMethod it generates/returns the following error:

Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send. 
At line:1 char:13
+ $response = Invoke-RestMethod 'https://url/path/to/endpoint...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo           : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException.Microsoft.PowerShell.Commands.InvokeRestMethodCommand
 

Environment

Release : 4.3

Component : Process Automation

Cause

This can happen due to Powershell defaults and the need to enforce TLS1.2. 

Resolution

Add the following to the "Run Script" .ps1 script being run - prior to the Invoke-RestMethod cmdlet:

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