如何在主机控制台上显示运行空间子 powershell 对象流?

How to show runspace child powershell objects streams on host console?

我有一些 Powershell objects(使用 [PowerShell]::Create() 创建)作为我的 powershell 应用程序中的线程。

如何在调用程序的控制台上显示流数据(详细流和错误流),在 运行 本身期间,而不仅仅是在线程终止之后?

$VerbosePreference需要在线程环境上设置为"continue"。也可以应用在真正执行脚本之前的pipeline中:

$pipeline = [PowerShell]::Create()
$pipeline.RunspacePool = $pool

if ($PSBoundParameters['Verbose'].IsPresent) {
    $pipeline.AddScript({ $VerbosePreference = "Continue" }, $false).Invoke()
    $pipeline.Commands.Clear()
}

... $pipeline execution code ...