Your symptom implies that $ErrorActionPreference="Stop"
is in effect at the time function
Test-Validation
executes.
(Temporarily) set it to 'Continue'
to fix your problem – which in future versions will hopefully no longer required (see below).
The reason for the observed behavior is that, in Windows PowerShell and up to PowerShell (Coe) 7.1, using an error-stream redirection (2>
) makes PowerShell route an external program‘s stderr output through PowerShell’s error stream (see about_Redirection), and $ErrorActionPreference="Stop"
therefore throws a script-terminating error once the first stderr line is received.
This behavior is unfortunate, because stderr output from external programs cannot be assumed to represent an error condition, given that external programs in effect use stderr, the standard error stream, for anything that other than data, which includes status information, for instance.
PowerShell 7.2 and above change this behavior for the better: stderr output is no longer routed through PowerShell’s error stream, which means that:
-
Stderr lines are (fortunately) no longer collected in the automatic
$Error
variable. -
Preference variable
$ErrorActionPreference
no longer has any impact on stderr output from external programs. -
The automatic
$?
variable, which indicates the success status of the most recently executed statement, is no longer incorrectly set to$false
when the process exit code is0
and there also happens to be stderr output – though note that you can always infer success vs. failure of external programs via the automatic$LASTEXITCODE
variable