Invoke-WebRequest in the real world

When working with the cmdlet Invoke-WebRequest I have had some issues with the speed of downloading files. The lack of speed.

I’m using It to download files in some automation scripts and they are running in the background.

When downloading manually thru Chrome or Internet Explorer or Edge It was pretty okay download time. But when I used Invoke-WebRequest It took longer time.

In the beginning I did not care because the automation went so much faster then doing It all manually.

Later on I started to do some research. I had one result when using the PowerShell console, another using PowerShell ISE and another using PowerShell Studio.

And the answer on “why does It take longer with Invoke-WebRequest then It should?” is the progress bar. It will be there in the background working even if you run your script in the background.

There are some variables that customize the behavior of PowerShell.
The preference variables.

And there are one for the progress. $progressPreference.


So I have changed my downloading function code when downloding stuff with Invoke-WebRequest to something like this:

And now It’s much faster.
An example with downloading iTunes.

With the progress
Without the progress

So If I need to download 10 applications in the same size and It will go like 4 min faster the second way, the automation will go 40 min faster. Thats pretty okay for just one variable.

It will go much faster some times and just faster sometimes. It’s internet and other stuff can do there to the time.

You may also like...

1 Response

  1. Henke says:

    That’s quite a difference and a sweet trick!

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.