Hello Experts,
I have a simple PowerShell REST script that works fine on my PC, but throws an Invalid Operation error when run on a server.
#Epicor user name
$user = "xxxxx"
#Epicor Password
$pass= "xxxxxx"
#BAQ End point URL
$uri = "https://xxxxxxxx/server/api/v1/BaqSvc/zCustomer01/"
#Create encoded password
$secpasswd = ConvertTo-SecureString $pass -AsPlainText -Force
#Create Credential
$cred = New-Object System.Management.Automation.PSCredential ($user, $secpasswd)
#Rest Call
$data = Invoke-RestMethod $uri -Method Get -Credential $cred -ContentType "Application/Json"
The error text is:
Invoke-RestMethod : The underlying connection was closed: An unexpected error occurred on a send.
At M:\Kinetic2023Upgrade\MRP Logs\Download MRP Files R0.ps1:16 char:9
+ $data = Invoke-RestMethod $uri -Method Get -Credential $cred -Content ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The PC is Win 10 running PowerShell 5.1
The server is Win Server 2012R2 running PowerShell 5.0
Both are on the same Active Directory network.
Our Epicor instance in Public Cloud, not On-prem.
I can run the commands successfully in Swagger and Postman (from a Postman web page) on the server. But the same PowerShell script that runs in Win 10 produces that error on the Server.
Where should I look to troubleshoot further?