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

Quick 1-Liner to List Domain Controllers and ReadOnly Statuses

PS C:\WINDOWS> Get-ADDomainController -Filter * | select Name,IsReadOnlyName       IsReadOnly----       ----------MONKEY       FalseBABOON       FalseGIRAFFE      FalseLION   FALSEKIMCONNECT   TrueKIMDISCONNECT TrueWHAT        TrueNOWAY        TrueWEBDC01      TrueWEBDC02      TrueSSO01        True

PowerShell: Update Local Windows Machine

This script is meant to be ran on a local computer. To update remote machines,…

PowerShell: Take VM Snapshots

# takeVmSnapshot.ps1 $vmNames='Test-VM1','Cowabunga-VM4' $snapShotLabel="Snapshot $(get-date -Format yyyyMMddTHHmmss)" function takeVmSnapshot([string[]]$vmName,[string]$snapshotLabel){ $vmClusterNodes=Get-ClusterGroup|?{$_.GroupType -eq 'VirtualMachine'} foreach ($vm in…