Posted On April 2, 2019

PowerShell: Methods to Download Files

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Methods to Download Files
# Change these values to reflect your desired downloads
$fileURL = "https://download.microsoft.com/download/0/d/9/0d9d81cf-4ef2-4aa5-8cea-95a935ee09c9/PortQryV2.exe"
$output = "C:\WINDOWS\System32\SysInternals\portqry.exe"

1. Start-BitsTransfer (my favorite. Works great for downloading huge service packs)
Import-Module BitsTransfer
Start-BitsTransfer -Source $fileURL -Destination $output -Asynchronous

2. Using Invoke-WebRequest (works fine for small downloads)
Invoke-WebRequest -Uri $fileURL -OutFile $output

3. System.Net.WebClient (a .NET class included in PowerShell. Compatible with Azure Automation runbooks and Server Core)
(New-Object System.Net.WebClient).DownloadFile($fileURL, $output)

4. wget (just a wrapper for Invoke-WebRequest -URI in PowerShell)
wget $fileURL #fetches the html header along with other stats

Leave a Reply

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

Related Post

PowerShell: Set DNS Records on Remote Computers

# setDnsEntries.ps1 $computernames=@( "$env:computername" ) $dnsServers=@( "8.8.8.8", "4.4.2.2" ) $results=[hashtable]@{} foreach ($computername in $computernames){ $psSession=new-pssession…

Installing DotNet 3.5 on Windows with Restricted Internet Access

# Set Windows Source files # Assuming that a Windows ISO / DVD Rom have…

Windows Activation Methods

Overview: 1. Retail:- There are 'lifetime' and 'limited' (1-2 years) variants- This can be used…