PoshBytes: Stop Clicking Download. Use Invoke-WebRequest

PoshBytes: Stop Clicking Download. Use Invoke-WebRequest

Learn how to download files directly in PowerShell using Invoke-WebRequest. This quick demo shows simple and repeatable ways to grab files without a browser.

This post is a companion for the video embedded below. Scroll down to see the code from the video.

https://youtube.com/shorts/tcBerDZORMo

You ever download a file, move it, rename it, then realize you have to do that 12 more times?

Yeah… let’s not live like that.

Download a file the simple way

PowerShell has a built-in way to grab files straight from the internet. No browser. No clicking. No more junk filling up your “Downloads” folder.

# Download directly to a path
$uri = "https://people.sc.fsu.edu/~jburkardt/data/csv/airtravel.csv"
Invoke-WebRequest -Uri $uri -OutFile ".\airtravel.csv"
Import-Csv -Path .\airtravel.csv

That’s it. You just replaced about 6 manual steps with one line.

No moving files later. No “where did that go?” moment.

Use variables for repeatable downloads

Now let’s pretend you’re doing this more than once. Because chances are, you are.

In this case you can extract the file name directly from the URI using Split-Path.

# Download multiple files
$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
    Invoke-WebRequest -Uri $file -OutFile "C:\Temp\$name"
}

Get-ChildItem -Filter 'PowerShell*'

That turns a load of clicking into a repeatable process.

Wrap Up

• Invoke-WebRequest downloads files directly from a URL
• Use -OutFile to control where the file goes
• Variables make downloads reusable and clean
• Loops let you download multiple files with minimal effort

Leave a Reply

Your email address will not be published. Required fields are marked *