Downloading files via PowerShell

I have long used WGET to download files from the internet, it has tons of options and made downloading in the background easy, large files, lots of files, incremented names, and even entire websites.
I recently ran into a problem where WGET would download a file, and then hang without finishing. If I used CTRL+C, the download finished and the file was usable, but it was a pain so I started looking to see what else there may be. (NOTE: it turned out to be a version issue, downloading the latest build fixed it).

I came across a post of using PowerShell to download files, and it was easy and flexible:

$client = new-object System.Net.WebClient

Another requirement for me is to use a proxy when I’m at work, a little more searching and I found with the below example:

# .NET class 
$webClient = new-object System.Net.WebClient 
# specify your proxy address and port 
$proxy = new-object System.Net.WebProxy “”  
# replace your credential by your domain, username, and pasword 
$proxy.Credentials = New-Object System.Net.NetworkCredential (“DomainUserName”, “Password”) 
# specify an header if you want to check info in your logs on your proxy 
$webClient.Headers.Add(“user-agent”, “Windows Powershell WebClient Header”) 
# File to download 
$url = “” 
# file path on your local drive 
$localfilename = “” 
# action !!!!  
$Webclient.DownloadFile($url, $localfilename) 

Now I can download files through my proxy, and automate the process to allow me to download multiple files simultaneously.

Leave a Reply