2

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?

iTayb
  • 12,373
  • 24
  • 81
  • 135

1 Answers1

2

$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 ...
iTayb
  • 12,373
  • 24
  • 81
  • 135