Run Curl Command in PowerShell

Run Curl Command in PowerShell

In PowerShell 3.0 and higher, we have Invoke-WebRequest and Invoke-RestMethod cmdlets; curl is an alias of the Invoke-WebRequest in PowerShell. Most learners make it confused with the Invoke-RestMethod cmdlet. In PowerShell 7 and higher, the Invoke-RestMethod cmdlet is the default cmdlet for sending RESTful web service requests.

It is another built-in cmdlet in PowerShell mainly designed for working with RESTful APIs and web services. It makes sending and handling web requests simple by automatically parsing the response as XML or JSON and supports basic OAuth authentication and basic authentication.

However, the Invoke-WebRequest and curl are still available in PowerShell, which sends HTTPS and HTTP requests to the APIs and web servers. The Invoke-WebReqest cmdlet provides more flexibility than the Invoke-RestMethod cmdlet in handling non-HTTP protocols and customizing requests.

Do you still need clarification? Want to check the aliases of the commands? You can use the Get-Alias cmdlet to get all the aliases with respective names, versions, and sources in PowerShell. However, Get-Comman curl will only show the alias with the respective command, version and source.

So, using native PowerShell cmdlets will be more appropriate than using aliases. However, we will learn both (Invoke-WebRequest and curl) and let you choose based on your requirements.

Using Invoke-WebRequest Cmdlet

Use the Invoke-WebRequest cmdlet to retrieve data from the specified URL in PowerShell.

Alternatively, we can use Invoke-WebRequest as iwr to avoid keystrokes. Using iwr will not affect the results; we will still get the same output.

Using curl Command

Use the curl cmdlet to retrieve data from the specified URL in PowerShell.

That’s all about how to run curl command in PowerShell.

Was this post helpful?

Leave a Reply

Your email address will not be published. Required fields are marked *