How to Run Curl Command in PowerShell
Windows operating system supports a number of command-line tools that can be very useful in automation. curl
is one of these useful tools that can be used to make requests from or to a server via any of the supported protocols such as HTTP, HTTPS, FTP, FTPS, SMTP, etc. This command-line tool supports some of the additional features like FTP upload, proxy support, resume transfer and limited bandwidth.
From the windows official build 1804, curl
has been added to its tool-chain. You can check this by opening the windows command prompt and running the following command.
curl --version
Output:
curl 7.55.1 (windows)
The output might be changed based on your curl installation.
the curl
in Windows PowerShell
In Windows PowerShell, you have to use the curl
command in a slightly different way than in the Windows command prompt. Because the curl
command is mapped as an alias to the Invoke-WebRequest
cmdlet. You can verify this by running the following command in a PowerShell window.
Get-Alias -Name curl
Output:
CommandType Name Version Source
----------- ---- ------- ------
Alias curl -> Invoke-WebRequest
All these commands will be resolved in the PowerShell command execution process. Usually, the aliases have the highest priority. Therefore, you should use the curl.exe
executable directly in the PowerShell instead of curl
. You can use the Get-Command
cmdlet to see how these two commands resolve in the runtime.
Get-Command curl
Output:
CommandType Name Version Source
----------- ---- ------- ------
Alias curl -> Invoke-WebRequest
Get-Command curl.exe
Output:
CommandType Name Version Source
----------- ---- ------- ------
Application curl.exe 7.55.1.0 C:\Windows\system32\curl.exe
The conclusion is that if you need to use the curl
(as same as in the Windows command prompt) in PowerShell then you need to call the curl executable(curl.exe
) directly. Else, you should stick to the PowerShell curl
alias which resolves to the Invoke-WebRequest
cmdlet under the hood.
the curl
Syntax in PowerShell
curl.exe [options] <url>
You can run the following command to get more information on curl
command and its options such as -a
, -C
, etc…
curl.exe --help
Output:
Usage: curl [options...] <url>
-a, --append Append to target file when uploading
.
.
.
-C, --continue-at <offset> Resumed transfer offest
Example Scenarios
Displays the HTML web page returns as the response.
curl.exe https://www.google.com
Displays the response, request header and and response header.
curl.exe -v https://www.google.com
Displays the header information.
curl.exe -I https://www.google.com
Saves the Header information to a file called file1.txt
.
curl.exe -I https://www.google.com -o file1.txt
Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.