The following command does not show the error message, which is what I want:
Copy-Item "C:\Folder I Have Access To\*" "C:\Folder I Do Not Have Access To" -ErrorAction SilentlyContinue
The following command does show the error message, which is not what I want:
Copy-Item "C:\Folder I Have Access To\*" "C:\Folder I Do Not Have Access To" -Force -ErrorAction SilentlyContinue
This is because I'm using the "Force" parameter. Is there a way I can use the "Force" parameter and still not show the error message?
This value is rarely used. -ErrorAction:SilentlyContinue suppresses the error message and continues executing the command. -ErrorAction:Stop displays the error message and stops executing the command. -ErrorAction:Suspend is only available for workflows which aren't supported in PowerShell 6 and beyond. Note.
The PowerShell ErrorAction parameter allows handling the actions if any error occurs. By default, PowerShell operates on the continue option for error handling. However, the ErrorAction operator can be used to change the default option.
If you need to suppress an error, you can use the ErrorAction switch to suppress an error for a single cmdlet or an ErrorAction preference variable to suppress errors globally.
Add this first.
$ErrorActionPreference = "silentlycontinue"
Can you try this :
trap
{
continue
}
Copy-Item "C:\Folder I Have Access To\*" "C:\Folder I Do Not Have Access To" -Force -errorAction SilentlyContinue
or
try
{
Copy-Item "C:\Folder I Have Access To\*" "C:\Folder I Do Not Have Access To" -Force -errorAction SilentlyContinue
}
catch
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With