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.
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.
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.
Start-BitsTransfer to Copy Files in PowerShell
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 [-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>]
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
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
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.