-ErrorAction Stop not work in Copy-Item

Question:

Simple script:

I have this output:

Why I get “hello” in output ?? -ErrorAction Stop not work??

update:

this code:

worked as expected. there isn’t “hello” in output.

Copy-Item ignore -ErrorAction and use only $ErrorActionPreference ??

Answer:

As indicated by the help the ErrorAction parameter has no effect on terminating errors, which yours is.

Source: Get-Help about_commonparameters and http://technet.microsoft.com/en-us/library/dd315352.aspx

Source:

-ErrorAction Stop not work in Copy-Item by licensed under CC BY-SA | With most appropriate answer!

Leave a Reply