About curl And PowerShell
[C#, .NET]
In a previous blog post I had talked about how curl
in Powershell was an alias for the Invoke-WebRequest cmdlet.
This was a well intentioned move, leveraging the muscle memory of experienced users.
The problem is that curl the tool is a very comprehensive tool, and an immediate problem that people with Linux experience ran into was that invoke-webrequest
does not recognize the bewildering array of parameters and sub-commands that curl
supports.
This led to a situation where scripts would surprise users, especially experienced users.
Microsoft made a change from Windows build 1804, where they made the following changes in PowerShell
- Removed the
curl
alias - Packaged with Windows the native curl executable
You can verify this if you are running a recent build by running the following command in your console:
curl --version
You should get back a response like this:
curl 7.79.1 (Windows) libcurl/7.79.1 Schannel
Release-Date: 2021-09-22
Protocols: dict file ftp ftps http https imap imaps pop3 pop3s smtp smtps telnet tftp
Features: AsynchDNS HSTS IPv6 Kerberos Largefile NTLM SPNEGO SSL SSPI UnixSockets
You can even check where it is installed:
where.exe curl.exe
You should get back a result like this:
C:\Windows\System32\curl.exe
You can now comfortably use curl in your Powershell scripts with the full features it supports, or if you wish, directly use invoke-webrequest
.
This change was made to both Powershell and Powershell Core.
Happy hacking!