Using PowerShell to Download a File from the Web

In this article, we’ll take a look at how to use native PowerShell cmdlets to download a file via HTTP, HTTPS, or FTP protocol. You can use PowerShell cmdlets as a native alternative of the wget and curl tool on Windows 10 and Windows Server 2016.

First, check the PowerShell version installed on your computer:


download file powershell

For versions of PowerShell earlier than 3.0, the System.Net.WebClient class must be used to download a file from the Internet. For example, on Windows 7/Windows Server 2008 R2 (on which PowerShell 2.0 is installed by default), you can use the following PowerShell commands to download a file from the HTTP(S) website and save it to a local drive:

$download_url = ""
$local_path = "C:\PS\theitbros_logo.png"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($download_url, $local_path)

powershell download file from url

To download a file from an FTP server with authorization, you need to specify the FTP username and password in the script:

$download_url = ""
$local_path = "C:\Downloads\psp9.2.iso "
$user = "hpeFtpUserName"
$pass = "Str0ng3$tPa$$"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object System.Net.NetworkCredential($user, $pass)
$WebClient.DownloadFile($download_url, $local_path)

On Windows 10, you can use the built-in Invoke-WebRequest cmdlet to download files (this cmdlet is available in all versions since PowerShell 3.0). To download a file, you just need to specify its URL and the local folder in which to save the file:

Invoke-WebRequest -OutFile C:\ps\logo.png

Hint. By default, the Invoke-WebRequest cmdlet downloads the file to the current directory. If you need to change the directory and/or file name, use the –OutFile parameter.

On Windows 10, there are two aliases available for the Invoke-WebRequest cmdlet: curl and wget.

READ ALSO  Accessing Domain Controller from Local DSRM Account

wget powershell

So, to download a file from the Internet website, you can use a shorter command. Instead of typing a full cmdlet name, you can use (for example):

wget -OutFile C:\downloads\

Hint. The Invoke-WebRequest doesn’t perform a check if the target file exists. If the file already exists, it is overwritten without any warning.

If you need to authenticate under the current user on a remote website (via NTLM or Kerberos), you need to add the –UseDefaultCredentials parameter:

Curl 'http://theitbros.local/' -UseDefaultCredentials

Or you can specify credentials manually:

Credentials = Get-Credential

Invoke-WebRequest -Uri -OutFile C:\downloads\ -Credential $Credentials

You can additionally pass some information in the HTTP header request. For example, set the API key:

Invoke-WebRequest -H @{'apiKey'='keyValue'} -OutFile C:\ps\

If you need to download a list of files in a batch, save their URLs to a plain txt file and use the following command to start the download:

Get-Content urls.txt | ForEach-Object {Invoke-WebRequest $_ -OutFile $(Split-Path $_ -Leaf)}
Cyril Kardashevsky

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.