I use the .NET component in Powershell, which uses Trace.TraceWarning , Trace.TraceInformation , etc.
I want to print these traces to the console when I run my Powershell script.
This works when I use the component in the current session. For example, (simulating the effect of tracing), I get the output "Hello" to the console:
$listener = new-object "system.diagnostics.consoletracelistener" [System.Diagnostics.Trace]::Listeners.Add($listener) | Out-Null [System.Diagnostics.Trace]::TraceInformation("Hello")
But if I do the same in the Powershell job, I do not get any output, although the ConsoleTraceListener should write in STDOUT, which, in turn, I expected to get as a result of work. (Interestingly, Console.WriteLine does not work from a job - but Write-Host does).
I start my work like this:
$work = { $listener = new-object "system.diagnostics.consoletracelistener" [System.Diagnostics.Trace]::Listeners.Add($listener) | Out-Null [System.Diagnostics.Trace]::TraceInformation("Hello") } $job = Start-Job -RunAs32 -ScriptBlock $work $job | Receive-Job -Wait
source share