Skip to content

Instantly share code, notes, and snippets.

@davidmdem
Created April 26, 2017 19:27
Show Gist options
  • Select an option

  • Save davidmdem/e0d23666917e0873b3e18523d64212e6 to your computer and use it in GitHub Desktop.

Select an option

Save davidmdem/e0d23666917e0873b3e18523d64212e6 to your computer and use it in GitHub Desktop.
Copy a whole directory to another with progress indications
#
# Copy a whole directory to another with progress indications
# https://blogs.technet.microsoft.com/heyscriptingguy/2015/12/20/build-a-better-copy-item-cmdlet-2/
#
Function Copy-WithProgress {
[CmdletBinding()]
Param (
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] $source,
[Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)] $destination
)
$source=$source.ToLower()
$fileList=Get-Childitem $source -Recurse
$total=$fileList.count
$position=0
foreach ($file in $fileList) {
$filename=$file.Fullname.ToLower().Replace($source,"")
Write-Progress -Activity "Copying data from $source to $destination" -Status "Copying File $filename" -PercentComplete (($position/$total)*100)
Copy-Item $file.FullName -Destination "$destination$filename"
$position++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment