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

How To Add or Remove a Path in Windows Environmental Paths

There are 2 functions to Add and Remove, at your convenience: # addEnvironmentalPath.ps1 $pathToAdd='C:\Scripts' $pathToRemove='C:\Scripts'…

PowerShell: Enabling and Disabling Network Level Authentication (NLA)

NLA is Microsoft's answer to mitigate some DDoS attacks via remote desktop (RDP). It uses…

PowerShell: Backup, Archive, and Remove a Microsoft SQL Database

$sqlServer='sqlsherver007' $databaseName="someDatabaseName" $saCredential=get-credential $backupDestination="\\Archive03\MSSQL_Backups" function triggerSqlBackup($sqlServer,$databaseName){ # Ensure the the Jump Box has SQL PowerShell…