I need help understanding a strange output behavior when using the exit statement and pscustomobject.
Example, script.ps1:
'hello'
[pscustomobject]@{'foo'='bar'}
'world'
exit 123
Calling the script: powershell -file script.ps1
Only hello will be returned. Versions 5.1 and 7.1 both behave like this. Can it be explained, or is this something for the github guys to fix?
Edit, based on comments: Running it from within Powershell, it works as expected. Calling PowerShell with -Command .\script.ps1 it also works (the exit code is gone, though).
It is this combination that breaks the output: Using the exit statement and calling PowerShell with -File.
Thanks