Preference variables generally take effect in the scope in which they're defined, which appears not be the case for $ErrorView, which only honors it in an ancestral scope:
Steps to reproduce
& { Set-Variable -Scope 0 VerbosePreference Continue; Write-Verbose 'I will display.' }
& { Set-Variable -Scope 0 ErrorView CategoryView; Get-Item /NoSuchItem }
& { Set-Variable -Scope 1 ErrorView CategoryView; Get-Item /NoSuchItem }
Note: To re-run the test, start a new session, because the last command sets $ErrorView in the global scope.
Expected behavior
I will display.
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
Actual behavior
I will display.
Get-Item : Cannot find path '/NoSuchItem' because it does not exist.
At line:1 char:54
+ ... t-Variable -Scope 0 ErrorView CategorizedView; Get-Item /NoSuchItem }
+ ~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
+ FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.GetItemCommand
ObjectNotFound: (/NoSuchItem:String) [Get-Item], ItemNotFoundException
Setting $ErrorView in the same scope as the failing Get-Item command didn't take effect - contrast this with the $VerbosePreference variable.
Environment data
PowerShell Core v6.0.0-alpha (v6.0.0-alpha.18) on Darwin Kernel Version 16.5.0: Fri Mar 3 16:52:33 PST 2017; root:xnu-3789.51.2~3/RELEASE_X86_64
Preference variables generally take effect in the scope in which they're defined, which appears not be the case for
$ErrorView, which only honors it in an ancestral scope:Steps to reproduce
Note: To re-run the test, start a new session, because the last command sets
$ErrorViewin the global scope.Expected behavior
Actual behavior
Setting
$ErrorViewin the same scope as the failingGet-Itemcommand didn't take effect - contrast this with the$VerbosePreferencevariable.Environment data