How to Download Files from the Internet with PowerShell

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 to the maximum, 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 that we want to download and download it to the computer. However, we have surely encountered some problems when downloading a file. Or, for some reason, the browser does not work and we urgently have to download a file from the Internet.

Download Files from the Internet with PowerShell

And before we go crazy trying to find the best way to do it, we can choose the 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. Downloading the files does not require running the Windows console with Administrator permissions. If we prefer to avoid permission issues, for example, the commands will also work when opening the console with Admin permissions.

Abrir PowerShell con permisos de Admin

Once we have the PowerShell window open, we only have to know the URL of the file that 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 to execute must have is the following:

$client.DownloadFile("URL de descarga","Ruta, nombre y extensión del archivo")

Obviously we must change “download URL” for the URL from which we are going to download the file to the computer, and “Path, name and file extension” for 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.

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.

Descargar archivos con PowerShell

In case the server requires some kind of authentication, we can authenticate ourselves 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

Limitations

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 frequently. But not for day to day.

The downloads are not exactly fast, that’s for starters. In addition, we will not have any control over them (we cannot pause and resume, or even cancel) or have download validation systems. The functions that PowerShell offers us to download files from the Internet are rather reduced. Although they do their job.