I write a very simple powershell script to post a json string to server. I have a strange issue when I execute the script.
The server is inside our intranet, the firewall is disable for all intranet server.
I tried to execute the script in different places:
- Powershell window in my own computer (windows 7, powershel 5)
- Powershell ISE in my computer
- start powershell.exe in a command prompt in my own computer
start powershell.exe in a third party command prompt application in my own computer
Powershell window in a citrix seesion (windows 10, powershel 5)
- start powershell.exe in a command prompt in a citrix seesion
I checked all of 6 places have ExecutionPolicy "RemoteSigned",
But, I can only successfully execute the script in last 3 places,
In first 3 place, I get an error
Invoke-RestMethod : Unable to connect to the remote server
At F:\Temp\test.ps1:46 char:9
+ $resp = Invoke-RestMethod -Method POST -Body $result ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Invoke-RestMethod],
WebException
+ FullyQualifiedErrorId : System.Net.WebException,Microsoft.PowerShell.Com
mands.InvokeRestMethodCommand
Besides, I also tried Invoke-WebRequest
, I got same error message.
Any idea why this is happen? What should I do with it?