From b50b0be8b4ddd3f7041b106457bb52603c98bf38 Mon Sep 17 00:00:00 2001 From: CodingWonders <101426328+CodingWonders@users.noreply.github.com> Date: Wed, 2 Oct 2024 14:13:57 +0200 Subject: [PATCH] Improve error handling for file copy --- functions/private/Copy-Files.ps1 | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/functions/private/Copy-Files.ps1 b/functions/private/Copy-Files.ps1 index 33342916..82b14bfe 100644 --- a/functions/private/Copy-Files.ps1 +++ b/functions/private/Copy-Files.ps1 @@ -19,10 +19,10 @@ function Copy-Files { try { $files = Get-ChildItem -Path $path -Recurse:$recurse - Write-Host "Copy $($files.Count)(s) from $path to $destination" + Write-Host "Copy $($files.Count) file(s) from $path to $destination" foreach ($file in $files) { - $status = "Copy files {0} on {1}: {2}" -f $counter, $files.Count, $file.Name + $status = "Copying file {0} of {1}: {2}" -f $counter, $files.Count, $file.Name Write-Progress -Activity "Copy Windows files" -Status $status -PercentComplete ($counter++/$files.count*100) $restpath = $file.FullName -Replace $path, '' @@ -37,7 +37,7 @@ function Copy-Files { } Write-Progress -Activity "Copy Windows files" -Status "Ready" -Completed } catch { - Write-Warning "Unable to Copy all the files due to unhandled exception" - Write-Warning $psitem.Exception.StackTrace + Write-Warning "Unable to Copy all the files due to unhandled exception:" + Write-Warning $psitem.Exception.ToString() } }