Created
August 10, 2025 18:35
-
-
Save cpereira7/4baafb9245882d906a3dddca4922d170 to your computer and use it in GitHub Desktop.
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
| param ( | |
| [Parameter(Mandatory=$true)] | |
| [string]$source, | |
| [Parameter(Mandatory=$true)] | |
| [string]$destination | |
| ) | |
| # Get all files to be copied | |
| $files = Get-ChildItem -Path $source -Recurse -File | |
| $totalFiles = $files.Count | |
| $copiedFiles = 0 | |
| foreach ($file in $files) { | |
| $sourceFile = $file.FullName | |
| $destFile = $file.FullName.Replace($source, $destination) | |
| # Ensure the destination directory exists | |
| $destDir = [System.IO.Path]::GetDirectoryName($destFile) | |
| if (!(Test-Path -Path $destDir)) { | |
| New-Item -ItemType Directory -Path $destDir | Out-Null | |
| } | |
| # Copy the file | |
| Copy-Item -Path $sourceFile -Destination $destFile | |
| # Update progress | |
| $copiedFiles++ | |
| $progress = ($copiedFiles / $totalFiles) * 100 | |
| Write-Progress -Activity "Copying Files" -Status "$progress% Complete" -PercentComplete $progress -CurrentOperation $sourceFile | |
| } | |
| Write-Progress -Activity "Copying Files" -Completed | |
| Write-Output "Backup completed successfully!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment