Move-Item's -Verbose causes $ErrorActionPreference to be ignored
Move-Items's -Verbose parameter causes the global $ErrorActionPreference = "Stop" to be ignored. This is a bug. Here's a repro script:
$ErrorActionPreference = "Stop"
Write-Host "ErrorActionPreference is $ErrorActionPreference"
mkdir folder -ErrorAction SilentlyContinue | Out-Null
"" > a.txt
Copy-Item a.txt folder
Write-Host "About to trigger error"
Move-Item a.txt folder -Verbose | Out-Null
Write-Host "If you're reading this, then execution didn't stop!"
Write-Host "Remove the Verbose paramter and it does stop, like it should."
Gustavo Maia commented
Same behavior for Add-Computer cmdlet, where "-Verbose" overrides behavior from $ErrorActionPreference.
Using "-ErrorAction Stop" works find though.
It’s not just limited to Move-Item. This seems to affect most, if not all, cmdlets. But it also depends on what kind of error the cmdlet throws, for instance, $ErrorActionPreference is obeyed on New-Item’s “Illegal characters in path” error but is ignored on “The file ‘…’ already exists”.