Powershell

PowerShell cURL

cURL is an incredible tool used when sending or receiving HTTP requests. It is a simple yet potent command-line tool that supports significant protocols such as HTTP, HTTPS, GOPHER, IMAP, SMB, SMPT, POP3, etc.

However, curl may behave differently when you shift to Windows, especially in PowerShell.

This tutorial will discuss how you can use curl in PowerShell depending on the PowerShell version.

cURL on Windows – PowerShell 6.x and Above

If you are running PowerShell version 6.x and above, chances are very high that you have the cURL binary installed and available on your system.

You can check your PowerShell version with:

$PSVersiontTable
Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Microsoft Windows 10.0.25126
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

In the output above, we can see we are running PowerShell version 7.2.4.

We can verify that we have cURL installed with the command:

$ curl –version
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

We can verify we have cURL installed on our system from the output above.

As of PowerShell version 6.x, the curl command is no longer mapped to the alias of the Invoke-WebRequest command. Instead, it is a standalone binary with unique commands and operations.

cURL on Windows – PowerShell Below 6.x

In older versions of PowerShell, curl is available as an alias to the Invoke-WebRequest command.

You can verify this using the Get-Alias command:

$ Get-Alias -Name curl
CommandType     Name                                              
Alias           curl -> Invoke-WebRequest

Notice that curl is an alias.

Using cURL as an Alias

It is no doubt that curl as an alias will have a different syntax. So, let us discuss a few examples of how to use it.

To make a simple curl request:

curl https://google.com

To view the help of how to use the utility, use the command:

$ Get-Help curl

Installing cURL – Older Windows Version

In some instances, you may not have cURL installed on your system. To resolve that, you can perform the following:

  1. Map Invoke-WebRequest to the alias curl
  2. Install the latest version of PowerShell, which has curl installed by default.
  3. Install git for windows which brings lots of tools to Windows, including curl.
  4. Download and install curl manually with scoop or chocolaty

Conclusion

In this article, we explored how to use curl on Windows depending on the version of PowerShell installed.

We also illustrated how to get help for curl and Invoke-WebRequest commands.

About the author

John Otieno

My name is John and am a fellow geek like you. I am passionate about all things computers from Hardware, Operating systems to Programming. My dream is to share my knowledge with the world and help out fellow geeks. Follow my content by subscribing to LinuxHint mailing list