Using BITS to Download Files (Part 2)

by Mar 30, 2021

BITS (Background Intelligent Transfer System) is the technique used by Windows to download huge files such as operating system updates. You can use the service as well, for example to download files asynchronously. When you do this, you don’t need to wait for the download to complete, and you can even download super large files across multiple reboots and over the course of days. The download continues whenever the user has logged on again.

The example below downloads a NASA Mars report with low priority as an asynchronous background task:

$url = ''
$targetfolder = $env:temp
Start-BitsTransfer -Source $url -Destination $targetfolder -Asynchronous -Priority Low

The disadvantage of asynchronous BITS transfers is that you need to manually complete the file transfer because BITS is downloading the data to a hidden cache. It is up to you to run Get-BitsTransfer and determine the jobs that have completed, then complete the file transfer using Complete-BitsTransfer.

This example would check for any completed transfers and finalize the downloads:

Get-BitsTransfer |
  ForEach-Object {
    Write-Warning $_.FileList.RemoteName
  } | 
  Where-Object { $_.jobstate -eq 'Transferred'  } |
  ForEach-Object {
    #$_ | Select-Object -Property *
    $file = $_.FileList.LocalName
    Write-Warning "Copy file $file..."
    $_ | Complete-BitsTransfer

Windows is using the same technique to download the huge operating system updates. Provided you have Administrator privileges, you can check BITS transfers initiated by other users including the operating system:

PS> Get-BitsTransfer -AllUsers 

JobId                                DisplayName                                          TransferType JobState    
-----                                -----------                                          ------------ ------
18514439-0e92-4ca8-88b4-4b2aa0036114 MicrosoftMapsBingGeoStore                            Download     Sus...
9e76ff92-65e2-4b3c-bb01-263e485e986a Dell_Asimov.C18EE5B49BDB373421EFA627336E417FC7EBB5B3 Download     Sus...
7bd117fe-2326-4198-a2a6-884022acb3ad Dell_Asimov.F10AAAECCA3ED0E344B68351EB619B5356E6C3C5 Download     Sus... 

PS> Get-BitsTransfer -AllUsers | Select-Object OwnerAccount, Priority, FileList

OwnerAccount                  Priority FileList                                                              
------------                  -------- --------                                                              
NT AUTHORITY\NETWORK SERVICE    Normal {}                                                                    
NT AUTHORITY\SYSTEM         Foreground {}               
NT AUTHORITY\SYSTEM         Foreground {  

Twitter This Tip! ReTweet this Tip!