iTayb
iTayb

Reputation: 12743

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

I have some Powershell objects (created with [PowerShell]::Create()) acting as threads in my powershell application.

How can I show the streams data (Verbose and Error streams) on the invoker's console, during the run itself, and not only after the thread terminates?

Upvotes: 2

Views: 636

Answers (1)

iTayb
iTayb

Reputation: 12743

$VerbosePreference needs to be set to "continue" on the thread environment. It can be also applied to the pipeline before the real execution script:

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

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

... $pipeline execution code ...

Upvotes: 2

Related Questions