Sar
Sar

Reputation: 299

Remote server Run CMD in Powershell

I am trying to upload a Zip file via RestAPI in powershell and Powershell version I am using is 5.1.

since Invoke-restmethod in powershell 5.1 doesn't have -form option,I tried to run curl command in CMD using powershell.When I run it locally it's working correctly. But when i try to run it in a server(azure devops agent) I am getting error saying curl command is not recognized.

What am i missing here it's runs as expected when i try in vs code, but not when i run it from a server.

$header1 = "accept: application/json"
$header2 = "X-Authorization: $($token)"
$header3 = "Content-Type: multipart/form-data"
$body1 = "[email protected];type=application/x-zip-compressed"
$body2 = "actionIfExisting=Existing"
$body3 = "publicWorkspace=Public"
cmd.exe /c curl -X POST $uri -H $header1 -H $header2 -H  $header3 -F $body1 -F $body2 -F $body3

Upvotes: 0

Views: 623

Answers (1)

Sar
Sar

Reputation: 299

Luckily I had git installed in the server and I read in this stack overflow page that Git comes with preInstalled curl.exe. So I called the path where git has curl.exe and using & operator in powershell to execute the curl.exe directly in powershell itself.

& 'C:\users\git\mingw64\bin\curl.exe' -X POST $uri -H $header1 -H $header2 -H  $header3 -F $body1 -F $body2 -F $body3

Upvotes: 1

Related Questions