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

WinRM Management Consideration

Infrastructure needs to be able to leverage scripting automation to perform Vulnerability Remediation, Resource Provisioning,…

Quick 1-liner: get system model number

# the 1-linerwmic computersystem get model,name,manufacturer,systemtype# Get RAM DIMM Slotswmic memorychip get Capacity /format:list

Linux: Enable PowerShell Remoting WinRM Client on Ubuntu 20.04

This note is a work-in-progress as the NTLM authentication support module by Microsoft for Ubuntu…