退出代码没有冒泡

Exit code is not bubbled up

外.ps1:

& "$env:WINDIR\syswow64\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command "& '.\Inner.ps1'; Write-Host "BLOCK: $LastExitCode"; exit $LastExitCode"
Write-Host "OUTSIDE: $LastExitCode"

内.ps1:

exit 3

执行Outer.ps1输出:

BLOCK: 1
OUTSIDE: 1

什么,为什么? Inner.ps1 明显退出,退出代码为 3。有什么问题?

注意:如果我将 Inner.ps1 更改为 return 0,我会收到以下输出:

BLOCK: 0
OUTSIDE: 0

不知何故,除 0 之外的所有其他代码都默认为 1,为什么?

您有引用问题:

& "$env:WINDIR\syswow64\WindowsPowerShell\v1.0\powershell.exe" -NonInteractive -NoProfile -ExecutionPolicy Bypass -Command '& ''.\Inner.ps1''; Write-Host "BLOCK: $LastExitCode"; exit $LastExitCode'
Write-Host "OUTSIDE: $LastExitCode"