Created
April 26, 2017 19:27
-
-
Save davidmdem/e0d23666917e0873b3e18523d64212e6 to your computer and use it in GitHub Desktop.
Copy a whole directory to another with progress indications
This file contains hidden or 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
| # | |
| # 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