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

标签 powershell runspace

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

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

最佳答案

$VerbosePreference 需要在线程环境中设置为“继续”。它也可以应用于真正执行脚本之前的管道:

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

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

... $pipeline execution code ...

关于powershell - 如何在主机控制台上显示运行空间子powershell对象流?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31311734/

相关文章:

powershell - 如何根据用户输入重新启动powershell程序

PHP | Powershell脚本输出数据

c# - Powershell 如何知道在哪里可以找到要导入的模块?

powershell - 新的 PowerShell 7 ForEach-Object Parallel 是如何实现的?

c# - 从模块导入特定 cmdlet 以在 Runspacepool 中使用

c# - ImportPS 模块故障检测

excel - 复制粘贴 Powershell Excel 保留格式

windows - 在 Windows 批处理文件中的多个命令中使用 powershell 变量

excel - .Trim() 函数在 foreach 循环中使用时不起作用

c# - 如何托管Powershell脚本或应用程序,以便可通过WSManConnectionInfo访问它? (例如Office 365)