PowerShell BitsTransfer module
BITS (Background Intelligent Transfer Service) is the Windows service that downloads or uploads files in the background and resumes from the same point after a network drop or reboot. The BitsTransfer module drives it with only 8 cmdlets, built into Windows 10/11 and Server (PowerShell 5.1 and 7).
234.1 Why is it used?
- Reliable large downloads: resume with HTTP Range requests instead of starting over.
- Background transfers that can be paused, resumed and prioritised.
- Used by Windows Update, SCCM/Intune and scripts that pull installers.
- Office PC safety: only own jobs (DisplayName n234-lab) from a local lab server; Get-BitsTransfer always with -Name.
234.2 How it works
- Step 1
1.Start-BitsTransfer: the BITS service creates a job (JobState Connecting)
- Step 2
2.HEAD /data4mb.bin to 127.0.0.1:18234 (Docker proxy -> 192.168.255.10:80)
- Step 3
3.Server replies Content-Length: 4194304
- Step 4
4.BITS sends GET with a Range header for each chunk
- Step 5
5.Server answers 206 Partial Content with only that part
- Step 6
6.After Suspend/Resume or a network drop, BITS asks again only for the missing ranges
Server must support Content-Length and Range
234.3 Job states
| JobState | Meaning |
|---|---|
| Queued / Connecting | Job created, talking to the server |
| Transferring | Data is arriving |
| Transferred | All data arrived, file still a temp file |
| Acknowledged | After Complete-BitsTransfer: file at its final name |
| Suspended / TransientError | Paused / network gone, BITS retries itself |
| Error / Cancelled | Needs a manual fix / after Remove-BitsTransfer |
234.4 Synchronous download: Start-BitsTransfer
$base = 'http://127.0.0.1:18234'Measure-Command { Start-BitsTransfer -Source $base/data4mb.bin -Destination $dst\sync4mb.bin -DisplayName n234-lab }Get-Item $dst\sync4mb.bin | Select-Object Name,Length(Get-FileHash $dst\sync4mb.bin -Algorithm SHA256).HashGet-BitsTransfer -Name n234-lab -ErrorAction SilentlyContinue | Measure-Object(lab.sh) $ curl -sI http://127.0.0.1:18234/data4mb.binHTTP/1.1 200 OKAccept-Ranges: bytesContent-Length: 4194304PS> Measure-Command { Start-BitsTransfer ... }TotalSeconds------------ 0.91059Name Lengthsync4mb.bin 4194304PS> (Get-FileHash $dst\sync4mb.bin -Algorithm SHA256).HashC43EBDC7ED6C26A20EE80726CC7FB2ACBA4D21566A4E32900B97C716EF365144(server) $ sha256sum /srv/data4mb.binc43ebdc7ed6c26a20ee80726cc7fb2acba4d21566a4e32900b97c716ef365144Count----- 0- Without -Asynchronous the prompt returns only when done; the job completes itself, so the n234-lab count is 0.
- The SHA256 matches the server file exactly.
234.5 Asynchronous job: Get, Suspend, Add, Set
$job = Start-BitsTransfer -Source $base/data4mb.bin -Destination $dst\async4mb.bin ` -Asynchronous -DisplayName n234-labGet-BitsTransfer -Name n234-lab | Select-Object DisplayName,JobState,BytesTransferred,BytesTotalSuspend-BitsTransfer -BitsJob $job | Select-Object DisplayName,JobStateGet-BitsTransfer -Name n234-lab | Select-Object DisplayName,JobState,BytesTransferred,BytesTotalDisplayName JobState BytesTransferred BytesTotal----------- -------- ---------------- ----------n234-lab Connecting 0 4194304 DisplayName JobState----------- --------n234-lab Suspended DisplayName JobState BytesTransferred BytesTotal----------- -------- ---------------- ----------n234-lab Suspended 786432 4194304- -Asynchronous returns immediately with a job object.
- Suspended at 786432 of 4194304 bytes: stopped in the middle.
Add-BitsFile -BitsJob $job -Source $base/readme.txt -Destination $dst\readme.txt | Select-Object DisplayName,FilesTotalSet-BitsTransfer -BitsJob $job -Priority Low | Select-Object DisplayName,Priority,TransferTypeGet-BitsTransfer -Name n234-lab | Select-Object DisplayName,JobState,Priority,FilesTotalDisplayName FilesTotal----------- ----------n234-lab 2 DisplayName Priority TransferType----------- -------- ------------n234-lab Low Download DisplayName JobState Priority FilesTotal----------- -------- -------- ----------n234-lab Suspended Low 2- Add-BitsFile adds a second file to the same job (FilesTotal 2).
- Priority Low = uses only idle bandwidth, runs after High and Normal jobs.
234.6 Resume and Complete
Resume-BitsTransfer -BitsJob $job -Asynchronous | Select-Object DisplayName,JobStateGet-BitsTransfer -Name n234-lab | Select-Object DisplayName,JobState,FilesTransferred,FilesTotal,BytesTransferred,BytesTotalTest-Path $dst\async4mb.binComplete-BitsTransfer -BitsJob $jobGet-ChildItem $dst -File | Get-FileHash -Algorithm SHA256DisplayName JobState----------- --------n234-lab Connecting DisplayName : n234-labJobState : TransferredFilesTransferred : 2FilesTotal : 2BytesTransferred : 4194333BytesTotal : 4194333PS> Test-Path $dst\async4mb.binFalsePS> Complete-BitsTransfer -BitsJob $jobPS> Get-ChildItem $dst | Select-Object Name,Lengthasync4mb.bin 4194304readme.txt 29sync4mb.bin 4194304C43EBDC7ED6C26A20EE80726CC7FB2ACBA4D21566A4E32900B97C716EF365144 async4mb.bin1B2433D4252978A2E5D88E06A647FC5E069F52E25F20EF1330FFB51E42F78A2D readme.txt- Step 1
1.Start-BitsTransfer -Asynchronous (Connecting)
- Step 2
2.Suspend-BitsTransfer (Suspended, 786432 bytes)
- Step 3
3.Add-BitsFile + Set-BitsTransfer -Priority Low
- Step 4
4.Resume-BitsTransfer -Asynchronous -> Transferred
- Step 5
5.Test-Path is False: data still in a temp file
- Step 6
6.Complete-BitsTransfer -> files appear (Acknowledged)
234.7 Cancel: Remove-BitsTransfer
$c = Start-BitsTransfer -Source $base/data4mb.bin -Destination $dst\cancel.bin ` -DisplayName n234-lab -Asynchronous -SuspendedGet-BitsTransfer -Name n234-lab | Select-Object DisplayName,JobState,BytesTransferred,BytesTotalRemove-BitsTransfer -BitsJob $c -WhatIfRemove-BitsTransfer -BitsJob $cGet-BitsTransfer -Name n234-lab -ErrorAction SilentlyContinue | Measure-ObjectTest-Path $dst\cancel.binDisplayName JobState BytesTransferred BytesTotal----------- -------- ---------------- ----------n234-lab Suspended 0 18446744073709551615PS> Remove-BitsTransfer -BitsJob $c -WhatIfWhat if: Performing the operation "Clear" on target "BitsTransfer".PS> Remove-BitsTransfer -BitsJob $cCount----- 0PS> Test-Path $dst\cancel.binFalse- A -Suspended job has not checked the size yet, so BytesTotal shows 18446744073709551615.
- Remove-BitsTransfer cancels the job and deletes its temp files; cancel.bin was never created.
- -WhatIf / -Confirm are the common parameters of this module.
234.8 Remaining options (docs)
Get-BitsTransfer -Name testjob1 | Complete-BitsTransferImport-CSV filelist.txt | Add-BitsFile -BitsJob $BitsSet-BitsTransfer -BitsJob $Bits -Priority HighGet-BitsTransfer -AllUsers -Name "*Microsoft*", "*Windows*" # admin| Option | Meaning |
|---|---|
| -BitsJob | Mandatory for Add/Complete/Remove/Resume/Suspend/Set; can be piped from Get-BitsTransfer |
| -TransferType | Download | Upload | UploadReply (upload = one file, needs IIS BITS extension) |
| -Priority | Foreground (default) | High | Normal | Low |
| -RetryInterval / -RetryTimeout | Min 60 s, default 600 s / default 1209600 s (14 days) |
| -ProxyUsage | SystemDefault | NoProxy | AutoDetect | Override (+ -ProxyList, -ProxyBypass) |
| -Credential / -Authentication | Server credentials |
| -AllUsers | Jobs of all users (admin); output shows OwnerAccount (domain\user) |
| -SetOwnerToCurrentUser | Set-BitsTransfer: make the current user the job owner |
234.9 Common mistakes
- Thinking BITS always uses idle bandwidth: default priority is Foreground, which competes with other apps; use Normal or Low.
- Forgetting Complete-BitsTransfer on an async job: the file stays a temp file.
- Running Get-BitsTransfer without -Name on a shared PC: it lists other jobs and their URLs.
- Running -AllUsers | Remove-BitsTransfer on an office PC: cancels everyone's jobs.
234.10 Interview tips
- Reliable download: Start-BitsTransfer -Asynchronous -DisplayName, poll Get-BitsTransfer -Name, then Complete-BitsTransfer.
- BITS resumes with HTTP Range requests (206 Partial Content).
- Transferred is not done: Complete moves the file to its final name.
- TransientError = BITS retries by itself (RetryInterval/RetryTimeout).