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: Windows Session Memory Usage Watcher

# windowsSessionWatcher.ps1 $serverNames=@( 'IRV-RDS01.domain1.net', 'LAX-RDS02.domain2.com ) $thresholdMemoryUsagePercent=30 $thresholdMemoryGb=20 $domainCreds=@( @{domain='domain1.ad';username='domain1\sysadmin';password=$env:pass1} @{domain='domain2.com';username='domain2\sysadmin';password=$env:pass2} ) # Email relay…

PowerShell: Get CRC Signature of a File

2/10/20 Update: xxHash will beat both of these in term of speed. Hence, this blog…

IIS Mime Types

One of the features of IIS security is to enforce file access by its associated…