PowerShell: ErrorAction set to "SilentlyContinue" not working

The following command does not display the error message I want:

Copy-Item "C:\Folder I Have Access To\*" "C:\Folder I Do Not Have Access To" -ErrorAction SilentlyContinue 

The following command shows an error message that 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 use the Strength parameter. Is there a way I can use the "Force" parameter and still not show the error message?

+4
source share
3 answers

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 { } 
+5
source

Add this first.

 $ErrorActionPreference = "silentlycontinue" 
+5
source

I just accidentally stumbled upon your post when I was looking for the answer to my question. This message seems to be an error, although it does speak of the "Verbose" option, which can apply to -force as well.

https://social.technet.microsoft.com/Forums/windowsserver/en-US/b76eccae-4484-43ec-a3dc-d4bc581124c2/adding-verbose-to-a-cmdlet-prevents-script-from-terminating-on- error? forum = winserverpowershell

0
source

All Articles