Until PowerShell 7, containing a statement within parentheses (...), subexpression syntax $(...) or array expression @(...) always reset $? to True , so that (Write-Error) shows $? as True. This has been changed in PowerShell 7, so that $? will always reflect the actual success of the last command run in these expressions.