起初我对 PowerShell ScriptBlock 很兴奋,但最近我对它在块内的执行顺序感到困惑。例如:
$test_block = {
write-host "show 1"
ps
write-host "show 2"
Get-Date
}
Run Code Online (Sandbox Code Playgroud)
调用 $test_block.Invoke() 的输出:
show 1
show 2
<result of command 'ps'>
<result of command 'get-date'>
Run Code Online (Sandbox Code Playgroud)
输出内容的命令会先运行吗?