+4 votes
994 views
How to use cURL command with PowerShell and download files

in Windows 10 by (551k points)
reopened | 994 views

1 Answer

+5 votes
Best answer

1. How to use cURL in Windows PowerShell
2. How to delete a Windows alias
3. Alternatives to install cURL on Windows

Each operating system has its type of commands to perform administrative, support or management or daily use tasks. Some of these commands may be compatible between all systems, but most are not. One case of this is cURL, which we can use frequently in macOS, UNIX or Linux environments, but not in Windows, talking about versions before 5 of PowerShell ..

cURL is a command that is used frequently through command lines or scripts to transfer data to a computer. But even beyond this, cURL is used in other elements such as cars, televisions, routers or printers in order to execute the transfer of data from the Internet.

cURL is a free and open source software and its scope is so high that it supports protocols and files such as: DICT, FILE, FTP, FTPS, Gopher, HTTP, HTTPS, IMAP, IMAPS, LDAP, LDAPS, POP3S, RTMP, RTSP, SCP, SFTP, SMB, SMBS, SMTP, SMTPS, Telnet and TFTP, is also able to support SSL certificates, HTTP POST, HTTP PUT, FTP upload, HTTP based upload, proxies, HTTP / 2, cookies, authentication Username + password (Basic, Normal, Summary, CRAM-MD5, NTLM, Negotiate and Kerberos), curriculum transfer file, proxy tunneling and much more..

In order to use cURL in Windows PowerShell, in this case on Windows 10, we must validate the version of PowerShell which must be at least 5, to verify this we will execute the following:

 $ PSVersionTable.PSVersion 
image

By using cURL in Windows PowerShell we will give more functionality to this modern Microsoft management console.


1. How to use cURL in Windows PowerShell


To test cURL in Windows PowerShell, it will be possible to write a cURL command as one that downloads a file from a GitHub repository.
Step 1

For this case we can execute the following:
 curl http://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/mongodb-on-ubuntu/azuredeploy.json> azuredeploy3.json} 
image

We can see that this error is generated, but there is cURL being used as an alias. The aliases in Windows PowerShell give us the possibility to create shortcuts for more extensive commands in order not to enter all the complete syntax..

Step 2

We can use the Get-Alias ​​cmdlet and we will see the following. Let's note that on the line the cURL command is responsible for calling the Invoke-WebRequest command. image
Step 3

So that for cURL functions in the ideal way, just edit the syntax we have executed and it will only be necessary to execute the following in this case:
 “Https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/mongodb-on-ubuntu/azuredeploy.json” 
image
Step 4

Thus, in this way, we can use cURL in Windows PowerShell. We can see that the file has been downloaded in the indicated path, in this case System32 because PowerShell was run as administrator, worse we can choose the desired path:

image


2. How to delete a Windows alias

Step 1

In the case that we do not have a profile in Windows PowerShell, the first step to take will be to create one by running the following command:
 New-Item $ profile -force -itemtype file 
image
Step 2

Now, we will open this profile in the text editor by running the following:
 notepad $ profile 
In the deployed file we will paste the following. There we proceed to save the changes and close the notebook.
 remove-item alias: curl 

image

Next, we must execute the following command to reload the profile, or close and reopen Windows Powershell to update the changes.


3. Alternatives to install cURL on Windows

Step 1

A practical method to ensure that cURL is installed in our system is by accessing the following link and downloading there:
cURL for Windows

Another way to install cURL is using Chocolatey which can be analyzed in detail in the following link:

Chocolate and

Chocolatey is a Linux-like command-line package manager for Windows systems. We will open PowerShell as administrators and execute the following command:

 iex ((new-object net.webclient) .DownloadString ('https://chocolatey.org/install.ps1')) 
image
Step 2

Once we have installed Chocolatey, we can use it to install cURL and we must open and close PowerShell before this to apply the changes.

We will execute the following to install cURL. There we can run the script or not.

 choco install curl 
image
Step 3

Once the process is finished we will see the following: image
CURL tips
Below, we will see some useful tips on how to use cURL on Windows, and generally on other systems:

Basic Syntax:

 curl http: // url --output "Output file" 
Hide the cURL progress indicator: The cURL progress indicator allows us to see in detail the current progress of the download, if we want to hide it we can use the -so –silent parameter as well.
 curl http://solvetic.com --output File –silent 

Thus, we have seen several alternatives to install and use cURL in Windows PowerShell and take full advantage of this command.


by (3.5m points)
edited

Related questions

+4 votes
1 answer
asked Jun 4, 2020 in Windows 10 by backtothefuture (551k points) | 1.3k views
+5 votes
1 answer
asked Oct 4, 2019 in Linux / Unix by backtothefuture (551k points) | 233 views
+4 votes
1 answer
+5 votes
1 answer
+4 votes
1 answer
Sponsored articles cost $40 per post. You can contact us via Feedback
10,634 questions
10,766 answers
510 comments
3 users