PowerShell Copy Files Using Bits

Hello all.  You probably already know that with the release of PowerShell 2.0, Microsoft introduced a number of cmdlets that allowed you to start and manage Bits transfer jobs.  Having this functionality can be very advantageous to an admin especially when needing to perform large scale transfer jobs.  The Bits capability to continue transfer jobs even in the event of a minor service interruption is a favorable feature to the traditional SMB file copy in these types of scenarios.

Unfortunately, using the Start-BitsTransfer cmdlet can be tedious if you are setting up a job that requires many files in many folders and subfolders.  Natively, the cmdlet accepts a text file that is formatted to list a source and a destination to handle multiple files and folder types.  Your other option is to use wild cards to grab multiple files in a single folder.  You can read about the cmdlet here http://technet.microsoft.com/en-us/library/dd819420.aspx.

To combat this problem, I’ve created the CopyFiles-Bits function.  Using this function you can select a source directory and a destination directory to start a series of Bits transfer jobs to copy all files and folders in the source directory over to your destination directory while maintaining the same folder structure.


## Jason Kline
## CopyFiles-Bits.ps1
## 01/19/2015

function CopyFiles-Bits
# Set Parameters
Param (

# Read all directories located in the sorce directory
$folders = Get-ChildItem -Name -Path $source -Directory -Recurse

# Start Bits Transfer for all items in each directory. Create Each directory if they do not exist at destination.
Start-BitsTransfer -Source $Source\*.* -Destination $Destination
foreach ($i in $folders)
$exists = Test-Path $Destination\$i
if ($exists -eq $false) {New-Item $Destination\$i -ItemType Directory}
Start-BitsTransfer -Source $Source\$i\*.* -Destination $Destination\$i


All you need to do once you load the function is pass the -Source and -Destination parameters to CopyFiles-Bits and your transfer jobs will begin.

Coy Files PowerShell


Thanks all!

One thought on “PowerShell Copy Files Using Bits

Leave a Reply

Your email address will not be published. Required fields are marked *