Start-Job - 实时检索输出

D.R*_*.R. 5 powershell powershell-5.0

我们通过以下方式启动 Powershell 函数Start-Job,并希望在调用者中实时检索其输出。有没有一种好的方法可以Retrieve-Job在不循环调用的情况下做到这一点?

sir*_*ank 2

尝试这样的事情:

$appJob = Start-Job { foreach($i in 1..10) { Write-Output "Testing $i"; Start-Sleep 10 } }
$appJob.ChildJobs[0].Output
Run Code Online (Sandbox Code Playgroud)