scriptinglibrary icon indicating copy to clipboard operation
scriptinglibrary copied to clipboard

Consider Start-BitsTransfer for Download

Open darthmarx opened this issue 4 years ago • 4 comments

Hi,

please consider using Start-BitsTransfer for Downloads, as it is much faster.

darthmarx avatar May 02 '22 11:05 darthmarx

Hi DarthMarx, Thanks for your comment. Sorry I've totally missed it. Can you please provide more context or reference? What is exactly the script or function are you referring to? Regards

PaoloFrigo avatar Aug 01 '22 06:08 PaoloFrigo

This is the code I was referring to: https://github.com/PaoloFrigo/scriptinglibrary/blob/727e79e0320a4598c34f655d8bd332cabdec2d57/Blog/PowerShell/Install-WAC.ps1#L23

darthmarx avatar Aug 09 '22 14:08 darthmarx

Hi DarthMarx, Frankly, for small files I don't pay much attention to it, but I do know what is the performance issue you are experiencing and referring to is caused in this case, because I faced/solved this multiple times.

Bits in this scenario is not necessary much faster than Invoke-WebRequest, but what you see is the bottleneck caused by the progress bar that is more frequently updated by Invoke-WebRequest.

If you want to test it yourself run this following snippet removing the progress bar on both cmd-lets:

$WAC_Online = "http://aka.ms/WACDownload"
$WAC_Installer = "C:\windows\Temp\wac.msi" 

$ProgressPreference = 'SilentlyContinue'
Measure-Command{Invoke-WebRequest -Uri $WAC_Online -OutFile $WAC_Installer}

Measure-Command{Start-BitsTransfer -Source $WAC_Online -Destination $WAC_Installer}

In my tests Invoke-WebRequest was always faster. image

Bits is very convenient for larger files, but in this specific case I would still prefer invoke-webrequest. Let me know what you think.

Thanks, Regards

PaoloFrigo avatar Aug 24 '22 04:08 PaoloFrigo

I will mark this as resolved.

PaoloFrigo avatar Dec 11 '22 22:12 PaoloFrigo