PoshBytes: Download Large Files with Start-BitsTransfer
Learn when to use Start-BitsTransfer for reliable downloads in PowerShell. This demo shows how BITS can download files, run transfers in the background, and manage multiple jobs.
This post is a companion for the video embedded below. Scroll down to see the code and full transcript from the video.
Welcome to PoshBytes, where we automate the boring parts before they start filling out paperwork.
Invoke-WebRequest is great for quick downloads.
But say you have larger files, slower connections, or downloads you do not want to babysit.
That’s where Start-BitsTransfer earns its paycheck.
Download a file with BITS
BITS stands for Background Intelligent Transfer Service.
Which is a fancy way of saying Windows will handle the download without treating your network like it owes it money.
# Download a large file with BITS
$uri = "https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv"
Start-BitsTransfer -Source $uri -Destination ".\airtravel.csv"
Import-Csv -Path .\airtravel.csv
Just like Invoke-WebRequest, it downloads the file and saves it locally.
However, BITS is built for reliability. If the connection gets interrupted, it can resume instead of starting over.
Run multiple downloads asynchronously
You can also start downloads in the background and keep working.
# Start an asynchronous download
$files = @(
"https://github.com/PowerShell/PowerShell/releases/download/v7.6.1/PowerShell-7.6.1-win-x64.zip",
"https://github.com/PowerShell/PowerShell/releases/download/v7.6.1/powershell-7.6.1-1.cm.aarch64.rpm",
"https://github.com/PowerShell/PowerShell/releases/download/v7.6.1/powershell-7.6.1-linux-arm32.tar.gz"
)
foreach($file in $files){
$name = Split-Path $file -Leaf
Start-BitsTransfer -Source $file -Destination ".\$name" -Asynchronous
}
Each download becomes a BITS job.
You can check on them later with Get-BitsTransfer, and when they are done, Complete-BitsTransfer finalizes the files.
# Check the status later
Get-BitsTransfer | Select-Object DisplayName, TransferType, JobState
# Complete active BITS jobs
Get-BitsTransfer | Complete-BitsTransfer
It’s like delegating work to Windows, which is always exciting because sometimes Windows agrees.
One important note
Start-BitsTransfer is Windows-only.
So if you try this on macOS or Linux, PowerShell will just sort of stare at you.
For cross-platform scripts, use Invoke-WebRequest, curl, or wget.
Wrap Up
• Start-BitsTransfer is great for larger or unreliable downloads
• BITS can resume interrupted transfers
• Use -Asynchronous to run downloads in the background
• Get-BitsTransfer shows active transfer jobs
• Complete-BitsTransfer finalizes completed asynchronous downloads
• Start-BitsTransfer is Windows-only