PWRSHELL.COM


Powershell all the Things!

| HOME | ABOUT | BLOG | GITHUB | TWITTER |

Want to learn powershell? Get Powershell in a Month of Lunches

DOWNLOAD FILE WITH POWERSHELL


Published: 2022-4-4

While there are quite a few ways to download files with powershell, my usual go to if I’m limited to strictly powershell is Invoke-WebRequest.

Invoke-WebRequest https://urltofile.com/file -OutFile "C:\pathtofile.bleh"
        
While not as elegant as say wget or curl, it does the trick when there are no other options besides powershell.

Speaking of wget and curl, here are links for both.

They work extremely well with powershell and give you a ton more options.

https://eternallybored.org/misc/wget/

https://curl.haxx.se/windows/

Added fun bonus. Here’s a little function that gives downloading via Invoke-WebRequest a little boost:

function Download-File {
    Param ($url)
    $get_file_name = $url.Split("/")[-1]
    $ProgressPreference = 'SilentlyContinue'
    $file_size = (Invoke-WebRequest $url -Method Head).Headers.'Content-Length' 
    $file_size_mb = $file_size/1MB
    Write-Host  - $get_file_name
    Write-Host  - $file_size_mb Megabytes
    write-Host  - Downloading file........
    Invoke-WebRequest $url -OutFile $env:USERPROFILE\Downloads\$get_file_name
    write-Host  - Download Finished!
}

Share this page: Reddit | Twitter | Facebook

Copyright 2022 - pwrshell.com
~ Hand coded with organic home grown PHP and ♥ ~
chris(at)pwrshell.com