Powershell - Using BITS file transfer
To support me, you can subscribe to the channel, share and like the videos, disable your ad blocker or make a donation. Thank you!
Hello,
BITS (Background Intelligent Transfer Service) is a Windows service for performing data transfers. It allows you to: - Set a network bandwidth priority - Pause and resume a transfer - To transfer in synchronous or asynchronous mode. - Download or send data - Resume transfer after a restart
Perform a download with BITS.
$Params = @{ Source = ‘https://github.com/PowerShell/PowerShell/releases/download/v7.2.2/PowerShell-7.2.2-win-x64.msi’ Destination = ‘d:\PowerShell-7.2.2-win-x64.msi’ DisplayName = ‘Test Priority = ‘Normal } $job = Start-BitsTransfer @Params -Asynchronous
By default, the BITS transfer is performed in synchronous mode with high priority (foreground).
No wildcard for HTTP or HTTPS addresses
List transfers
Get-BitsTransfer
Display everyone’s BITS jobs
Get-BitsTransfer -AllUsers
Suspend a transfer
$job | Suspend-BitsTransfer
Resume a transfer
$job | Resume-BitsTransfer -Asynchronous
By default, the transfer is restarted in synchronous mode even if it was started asynchronously initially.
You can resume the transfer after a reboot
Complete completed transfers
Get-BitsTransfer | Where-Object Jobstate -eq Transferred | Complete-BitsTransfer
In asynchronous mode, a temporary file is created, Complete-BitsTranfer generates the final file.
If the final file is already present, it will not be overwritten and will remain in the temporary file state.
Recover a file from a share
$DriveParams = @{ name = ‘drive PSProvider = ‘FileSystem Root = ‘\10.0.0.253\iso’ cred = Get-Credential } New-PSDrive @DriveParams
It is necessary to create a drive otherwise a path not found error is returned
for the SMB path in Start-BitsTransfer
$Params = @{ Source = ‘drive:\en-en_windows_11_business_editions_x64_dvd_95aa5eee.iso’ Destination = ‘c:’ DisplayName = ‘Test2’ } Start-BitsTransfer @Params -Asynchronous
It is not necessary to specify the name of the destination file for UNC paths.
Add additional files to a job
$Params = @{ Source = ‘drive:\fr-fr_windows_server_2022_x64_dvd_9f7d1adb.iso’ Destination = ‘c:’ } Get-BitsTransfer -Name test2 | Add-BitsFile @Params Get-BitsTransfer -Name test2 | Select-Object displayname, filelist Get-BitsTransfer | Complete-BitsTransfer
Send a local file to a share
$Params = @{ Source = ‘C:\PowerShell-7.2.2-win-x64.msi’ Destination = ‘\10.0.0.253\iso’ DisplayName = ‘Test3’ } Start-BitsTransfer @Params -Asynchronous Get-BitsTransfer | Complete-BitsTransfer
Specify authentication parameters (Basic, Digest, NTLM, Negotiate or Passport)
Start-BitsTransfer -source http://10.0.0.1/fichier.iso -destination c:\temp\fichier.iso ` -asynchronous -Authentication NTLM -Credential (Get-Credential)
Modify a transfer in progress, the priority in this example :
$Job | Set-BitsTransfer -Priority Foreground
Delete the job
$Job | Remove-BitsTransfer
Delete all tasks for all users (whether in progress or not)
Get-BitsTransfer -Allusers | Remove-BitsTransfer -Confirm:$False
Transfer several HTTP(S) files from a CSV
Create a file (list.csv in the example) with the following contents:
Source,Destination https://serveur/fichier1.txt,c:\folderfile1.txt https://serveur/fichier2.txt,c:\dossier\file2.txt
Import-CSV list.csv | Start-BitsTransfer -Asynchronous Get-BitsTransfer | Select-Object displayname,filelist
Send several files to one share (or vice versa)
You can use wildcards with UNC paths
$Params = @{ Source = ‘C:\demo*’ Destination = ‘\10.0.0.253\iso’ DisplayName = ‘Test6’ } Start-BitsTransfer @Params -Asynchronous Get-BitsTransfer | Complete-BitsTransfer
Related links
Powershell - Compress-Archive and Expand-Archive to create and extract ZIP archives
Powershell, through the Microsoft.PowerShell.Archive module, allows us to create, update and extract ZIP archivesPowershell - Export-Csv versus Export-Clixml
Powershell - Export-Csv versus Export-Clixml, or the limits of Export-CsvPowershell - Overview of Where-Object basic syntax and its limitations
Powershell - Overview of Where-Object basic syntax and its limitationsPowershell - Hyper-V - Give a custom name to a virtual network adapter
Hyper-V defaults to naming virtual machine NICs as network adapters. This can make it difficult to identify their usage, but this problem can be solved with Powershell which allows you to change the name of virtual network adapters.Powershell - How to add and view a GPO description
How to add and view a GPO description in PowershellPowershell - Displaying and changing the power mode in Windows
How to display and modify the power mode in Windows with Powershell
Follow me on
Support me
Last content
Powershell - Compress-Archive and Expand-Archive to create and extract ZIP archives
Powershell - Export-Csv versus Export-Clixml
Powershell - Overview of Where-Object basic syntax and its limitations
Powershell - Hyper-V - Give a custom name to a virtual network adapter
Powershell - How to add and view a GPO description
Powershell - Displaying and changing the power mode in Windows
Powershell - Adding a line to a file from a specific line
Windows 11 - how to organise your Start menu