PowerShell Copy-Item Progress

Migel Hewage Nimesha Aug 26, 2022
PowerShell Copy-Item Progress

File copying is a regular activity involving transferring one or more files from the source to the destination. The source and destination can be the same host or two different hosts.

The Copy-Item is one of the basic cmdlets that every PowerShell user uses to copy files from one place to another. The only downside of Copy-Item is that it doesn’t display the operation’s progress as a progress bar or percentage.

The Start-BitsTransfer cmdlet becomes handy when you have a large number of files to work with, and the good thing is that it displays a progress bar that indicates the progress of the copy operation.

This article will focus on the Start-BitsTransfer cmdlet to copy files from source to destination.

Use Start-BitsTransfer to Copy Files in PowerShell

The Start-BitsTransfer cmdlet initializes a BITS job to copy one or more files from the source to the destination without hassle. Usually, the PowerShell becomes non-interactive when the cmdlet has initialized the BITS job.

Furthermore, the cmdlet accepts several optional arguments to improve the copy functionality. The following is the generic syntax for the Start-BitsTransfer cmdlet.

Start-BitsTransfer
[-Asynchronous]
[-Dynamic]
[-CustomHeadersWriteOnly]
[-Authentication <String>]
[-Credential <PSCredential>]
[-Description <String>]
[-HttpMethod <String>]
[[-Destination] <String[]>]
[-DisplayName <String>]
[-Priority <String>]
[-TransferPolicy <CostStates>]
[-ACLFlags <ACLFlagValue>]
[-SecurityFlags <SecurityFlagValue>]
[-UseStoredCredential <AuthenticationTargetValue>]
[-ProxyAuthentication <String>]
[-ProxyBypass <String[]>]
[-ProxyCredential <PSCredential>]
[-ProxyList <Uri[]>]
[-ProxyUsage <String>]
[-RetryInterval <Int32>]
[-RetryTimeout <Int32>]
[-MaxDownloadTime <Int32>]
[-Source] <String[]>
[-Suspended]
[-TransferType <String>]
[-CustomHeaders <String[]>]
[-NotifyFlags <NotifyFlagValue>]
[-NotifyCmdLine <String[]>]
[-CertStoreLocation <CertStoreLocationValue>]
[-CertStoreName <String>]
[-CertHash <Byte[]>]
[-WhatIf]
[-Confirm]
[<CommonParameters>]

The TransferType argument is used to specify the direction of the copy operation. It can be a download or an upload.

Let’s create a folder called codes in the D drive with nearly 300 text files. Furthermore, we will be creating another empty folder called copiedfiles.

Next, the Start-BitsTransfer command is used to copy files from the source folder codes to the destination folder copiedfiles. One thing to remember is to import the BitsTransfer module in advance.

Import-Module BitsTransfer
Start-BitsTransfer -Source "D:\codes\*.txt" -Destination "D:\copiedfiles\" -TransferType Download

Output:

Start-BitsTransfer

As you can see in the above figure, the progress bar appears when the copy operation starts. This is a very useful indicator for the end users to get an idea about the operation’s progress.

Migel Hewage Nimesha avatar Migel Hewage Nimesha avatar

Nimesha is a Full-stack Software Engineer for more than five years, he loves technology, as technology has the power to solve our many problems within just a minute. He have been contributing to various projects over the last 5+ years and working with almost all the so-called 03 tiers(DB, M-Tier, and Client). Recently, he has started working with DevOps technologies such as Azure administration, Kubernetes, Terraform automation, and Bash scripting as well.