PowerShell: How to efficiently download file with BitsTransfer

PowerShell: How to efficiently download file with BitsTransfer

PowerShell offers a powerful command-line tool for downloading files: the Background Intelligent Transfer Service (BITS). BITS is designed for efficient file transfers that don't interrupt network usage. This tutorial will guide you through using the Start-BitsTransfer cmdlet in PowerShell for downloading files, including handling multiple files and asynchronous downloads.

Getting Started with PowerShell

Open PowerShell: Access the PowerShell command-line interface from the Start menu or by entering powershell in the Run dialog (Win + R).

Steps to Download Files Using BitsTransfer

Downloading a Single File

Basic File Download: To download a single file, use the Start-BitsTransfer cmdlet. Replace the URL and destination path with your desired file and location.
  1. Start-BitsTransfer -Source "https://example.com/file.iso" -Destination "C:\downloads\file.iso"
Or, for a more streamlined syntax:
  1. Start-BitsTransfer "https://example.com/file.iso" "C:\downloads\file.iso"

Downloading Multiple Files

Multiple File Downloads: BITS can handle multiple file downloads simultaneously. Here's how to download two different files to specified paths:
  1. Start-BitsTransfer -Source "https://example.com/file1.iso", "https://example.com/file2.iso" -Destination "C:\downloads\file1.iso", "C:\downloads\file2.iso"

Asynchronous Download

Asynchronous Download: For non-blocking, asynchronous downloads, add the -Asynchronous parameter. This is particularly useful for large files or when performing other tasks.
  1. Start-BitsTransfer -Source "https://example.com/file.iso" -Destination "C:\downloads\file.iso" -Asynchronous

Monitoring Asynchronous Downloads

Check Download Progress: To monitor the progress of an asynchronous download, use Get-BitsTransfer.
  1. Get-BitsTransfer
Output:
  1. JobId DisplayName             TransferType           JobState           OwnerAccount
  2. ----------------------              ------------                --------              ------------
  3. 12345678-90ab-cdef-ghij-klmnopqrstuv           BITS Transfer Download           Transferring           UserName\YourAccount

Completing Asynchronous Downloads: Once the download is finished, finalize it with Complete-BitsTransfer.
  1. Get-BitsTransfer | Complete-BitsTransfer

Conclusion

This method is particularly effective for handling large file transfers, multiple files, and ensuring downloads continue without disrupting other network activities. BITS is a versatile tool for any system administrator's toolkit, enhancing file management capabilities within the PowerShell environment.


    • Related Articles

    • How to download files via BitsTransfer using PowerShell

      Introduction BitsTransfer is a module in PowerShell that utilizes the Background Intelligent Transfer Service (BITS) to transfer files between systems. It's a reliable way to download files, especially large ones, as it supports resuming transfers if ...
    • PowerShell Out-File: Harnessing the Power of Output Redirection in PowerShell

      Introduction PowerShell is a powerful scripting language and automation framework that offers a wide range of features to system administrators and students. One essential aspect of PowerShell is its ability to handle and manipulate output ...
    • PowerShell: Advanced Configuration of Windows Event Log File Size

      Managing the size and behavior of Windows Event Log files is crucial for system administrators. It ensures that logs are maintained within manageable sizes and are archived or overwritten according to specific needs. This tutorial provides an ...
    • 16. PowerShell - "Passthru" Parameter

      Introduction: PowerShell, Microsoft's versatile command-line shell and scripting language, empowers administrators and developers to automate and manage Windows systems efficiently. Parameters play a crucial role in PowerShell, facilitating data flow ...
    • 18. PowerShell - Drives and providers

      In the context of PowerShell, drives are logical data containers that provide access to various data sources, such as file systems, registry hives, and even Active Directory. These drives act as a consistent interface for administrators to interact ...