Last active
August 30, 2017 22:43
-
-
Save NathanTheGr8/a8fe34ac5d3de82b335014ea9772e36a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Copy-ItemWithBITS { | |
<# | |
.SYNOPSIS | |
Copy-Item using the BITS protocol | |
.DESCRIPTION | |
Works like the copy-item cmdlet but uses the Background Intelligent Transfer Service (BITS) protocol | |
.PARAMETER Source | |
The Path to the file/directory you want to transfer | |
.PARAMETER Destination | |
The path to where you want to transfer to | |
.EXAMPLE | |
Copy-ItemWithBITS -Source $Pwd -Destination C:\Temp | |
.NOTES | |
LICENCE MIT https://opensource.org/licenses/MIT | |
Requires BitsTransfer Module | |
#> | |
param( | |
[Parameter(Mandatory = $true, | |
Position = 0, | |
HelpMessage = 'The Path to the file/directory you want to transfer', | |
ValueFromPipeline = $True)] | |
[ValidateScript({Test-Path $_})] | |
[Alias('src')] | |
[string]$Source, | |
[Parameter(Mandatory = $true, | |
Position = 1, | |
HelpMessage = 'The Path to where you want to copy files', | |
ValueFromPipeline = $True)] | |
[ValidateScript({Test-Path $_})] | |
[Alias('dest')] | |
[string]$Destination | |
) | |
#Get all the items in the Source Folder/File | |
$Items = Get-ChildItem -Path $source | |
foreach ($Item in $Items){ | |
#if the item is not a folder | |
if (!($Item.PSIsContainer)){ | |
Start-BitsTransfer -Source $Item.Fullname -Destination $Destination | |
} | |
#else recursivily call | |
else { | |
#Make the a new folder in the Destination, don't show output | |
mkdir $Destination\$($Item.Name) | Out-Null | |
Copy-ItemWithBITS -Source "$Source\$($Item.Name)" -Destination "$Destination\$($Item.Name)" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment