PowerShell is the evolved version of CMD, a complete advanced console for Windows that allows us to configure and perform certain tasks in the Microsoft operating system in text mode. Although it does not reach the level of the Linux terminal, this console is very useful and powerful for making configurations that cannot be done from the interface and even for automating certain activities through scripts. This console has a large number of commands that allow us to control Windows as much as possible, to the point of being able to download files from the Internet from it.
The normal thing when we are going to download a file from the Internet is to do it from the browser. We select the file we want to download and download it to the computer. However, surely we have ever encountered some problems when downloading a file. Or maybe, for some reason, the browser does not work and we have to urgently download a file from the Internet.
And before we go crazy trying to find the best way to do it, we can go easy and turn to PowerShell.
Download files with PowerShell
We can easily open PowerShell by simply clicking on the Windows 10 search bar and searching for this program. To download the files it is not necessary to run the Windows console with Administrator permissions. If we prefer to save permission problems, for example, the commands will also work when opening the console with Admin permissions.
Once we have the PowerShell window open, we only have to know the URL of the file we want to download. Once we have it, we execute the following command in the PowerShell console to create a new instance and prepare the program to download the file from the Internet:
$client = new-object System.Net.WebClient
Next we will use the DownloadFile method to download the file. The structure that the command that we must execute must have is the following:
$client.DownloadFile("URL de descarga","Ruta, nombre y extensión del archivo")
Obviously we must change “Download URL” to the URL from which we are going to download the file to the computer, and “Path, name and file extension” to the directory where we want to save the file, along with its name and extension. Both the URL and the destination path of the command must be enclosed in double quotes, which are written with shift + 2.
We press «Enter» and the download will start automatically. We wait for it to finish and, when it finishes, the download will be in the directory that we have specified.
In case the server requires some type of authentication, we can authenticate with username and password directly from PowerShell by executing the following command after the “new-object” that we have explained before:
$client.Credentials = Get-Credential
Obviously, being able to download files from the Internet with PowerShell can get us out of some trouble. But it is not by far the best way to do it. This download system can be useful, for example, in scripts and automation tasks. Even to work with backups or remote files that are updated often. But not for the day to day.
Downloads aren’t exactly fast, that’s for starters. In addition, we will not have any control over them (we cannot pause and resume, or even cancel) nor do we have download validation systems. The functions that PowerShell offers us to download files from the Internet are rather limited. Although they fulfill their function.