How to Use the Curl Command in Powershell?

Am using the curl command in PowerShell to post the comment in bit-bucket pull request page through a Jenkins job. I used the below PowerShell command to execute the curl command, but am getting the error mentioned below. Could anyone please help me on this to get it worked?

$CurlArgument="-u :yyyy -X POST  --data content=success"
$CURLEXE='C:\Program Files\Git\mingw64\bin\curl.exe'
& $CURLEXE $CurlArgument

Error Details:

curl.exe : curl: no URL specified!
At line:3 char:1
+ & $CURLEXE $CurlArgument
+ ~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (curl: no URL specified!:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

curl: try 'curl --help' or 'curl --manual' for more information
2

4 Answers

Use splatting.

$CurlArgument = '-u', ':yyyy',
                '-X', 'POST',
                '
                '--data', 'content=success'
$CURLEXE = 'C:\Program Files\Git\mingw64\bin\curl.exe'
& $CURLEXE @CurlArgument
4

In Powershell 3.0 and above there is both a Invoke-WebRequest and Invoke-RestMethod. Curl is actually an alias of Invoke-WebRequest in PoSH. I think using native Powershell would be much more appropriate than curl, but it's up to you :).

Invoke-WebRequest MSDN docs are here:

Invoke-RestMethod MSDN docs are here:

2

Or another option you could just call curl.exe using splatting as follows.

> curl.exe '-u', ':yyyy',
 '-X', 'POST',
 '                
 '--data', 'content=success'

To know where is curl.exe using this command Get-Command curl.exe

Other option is to delete aliases curl command with Invoke-WebRequest

To see and delete aliaes in PowerShell

>Get-Aliases
>Remove-Item alias:curl

Then just runing command without '.exe'

> curl '-u', ':yyyy',
 '-X', 'POST',
 '                
 '--data', 'content=success'

I hope this would helps.

Instead of curl you can use this command:

(New-Object System.Net.WebClient).DownloadString("")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

David Miller

David Miller

Executive Financial & Market Analyst

David Miller brings 15 years of experience in global economics, personal finance strategy, and market dynamics. He specializes in turning complex economic trends into actionable insights for everyday readers.

Share this article
Twitter Facebook Pinterest