JKStinn
JKStinn

Reputation: 25

COPY-ITEM Passthru not working when encountering error

Within ISE, I've tried both the below. Neither is working. The only way is to clear $error and test after the copy attempt. Any suggestions?

$cpy = Copy-Item -Path "D:\~a\2K0NVK0.xt" -Destination "D:\~Bkup-F\2K0NVK10.txt" -Force -passthru -ErrorAction SilentlyContinue

if($cpy){ $cpy   # only displays on successful copy }

Try{
  Copy-Item -Path "D:\~a\2K0NVK0.xt" -Destination "D:\~Bkup-F\2K0NVK10.txt" -Force -ErrorAction SilentlyContinue
} Catch { write-host "Hit a bug!"   # not being displayed }

Upvotes: 0

Views: 236

Answers (1)

jay
jay

Reputation: 36

A try/catch only works when ErrorAction is set to Stop.

Upvotes: 1

Related Questions