How To Download A File With A PowerShell Command In Windows 10

Advertisement

Windows PowerShell comes bundled with Windows 10. You can even replace the Command prompt on the Power User menu with PowerShell. Like Command Prompt, PowerShell lets you perform a myriad of configuration actions on your desktop such as uninstalling default apps. You can also use to for something far more basic such as downloading a file. With a simple command, you can not only download a publicly available file but you can also download one that requires authentication before it can be downloaded such e.g. a file in your Dropbox folder. We’ve detailed the process here.

The commands you need are;

$client = new-object System.Net.WebClient
$client.DownloadFile("Download Link","File Destination")

In the above command you will replace ‘Download link’ with the link to the file you want to copy. The URL must be inside quote marks and brackets are part of the syntax. Replace ‘File Destination’ with the location you want to save the file to and then and extension of the file. You can specify any name you want but make sure you get the extension right. PowerShell will not create a folder so make sure the folder you want to save the file to already exists.

The command will look something like this;

$client = new-object System.Net.WebClient
$client.DownloadFile("http://i.imgur.com/JnphmRt.jpg","C:\Users\Fatima Wahab\Desktop\cat.jpg")

powershell download file

If you’re trying to download a file that requires you to sign in to a service, insert this command between the two lines;

$client.Credentials =  Get-Credential

An on-screen prompt will ask you to enter your login and password. You are going to have to know before hand which login and password to enter because the prompt will not tell you if it’s asking for your Google account or your Dropbox credentials.

The command, complete with the authentication command will look like this;

$client = new-object System.Net.WebClient
$client.Credentials = Get-Credential
$client.DownloadFile("http://i.imgur.com/JnphmRt.jpg","C:\Users\Fatima Wahab\Desktop\cat.jpg")

Make sure you have a direct link to a file. Links to pages with a download button will not work. Instead, you will either get an error or end up saving the page itself instead of the file.

Advertisement