Closely related: #4002; see also: #4332
By design, stderr output from external programs is not recorded in $Error by default.
Paradoxically, when you use 2>$null in order to explicitly suppress stderr output, it then is recorded in $Error, which is obviously not the intent.
Note: It also happens when you redirect to an actual file.
Steps to reproduce
$Error.Clear()
# Call `whoami` with an invalid argument, which produces stderr output (all platforms)
whoami badarg 2>$null
$Error.Count | Should -Be 0
Expected behavior
The test should succeed.
Actual behavior
The test fails with something like:
That is, stderr output was unexpectedly recorded in $Error.
Environment data
PowerShell Core 7.0.0-preview.5