Link to home
Start Free TrialLog in
Avatar of Isaiah Melendez
Isaiah Melendez

asked on

Powershell Script - Download File and Show Progress Bar

Hello, Experts!

I am needing a script help with showing a progress bar when downloading a big file.

Here is my script:

Invoke-WebRequest -Uri https://url/to/file/filename.7z -OutFile C:\temp\NLB.7z

Open in new window


I would like for when the download kicks off it shows a progress bar in the output window as to how far you are in the download.
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

I think is not an async call, so it basically blocked your console where you run it.

$uri= "https://download.teamviewer.com/download/TeamViewer_Setup.exe"
$out= "F:\TeamViewer_Setup.exe"

[System.Net.WebClient]$wc = new-object System.Net.WebClient
$wc.DownloadFileAsync($uri,$out)

Open in new window

this will create a background job that can be accessed using the regular event handling for .NET
Described here:
https://learn-powershell.net/2013/02/08/powershell-and-events-object-events/
Using that logic it can be archived the progress bar

You can subscribe these events and should register using PS commands.
$wc.DownloadProgressChanged
$wc.DownloadDataCompleted
ASKER CERTIFIED SOLUTION
Avatar of J0rtIT
J0rtIT
Flag of Venezuela, Bolivarian Republic of image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Isaiah Melendez
Isaiah Melendez

ASKER

This worked for me, thanks, Jose!