Please feel free to provide feedback or file bugs here.

Transcript does not log the Verbose and Warning stream of Receive-Job

Problem
------------------------------------------------------
When we run a job inside a transcript, the Verbose and the Warning streams of the jobs are not displayed in the transcript. However, we can see the in the console correctly.

Steps to reproduce
--------------------------------------------
Run the following script
Start-Transcript -Path 'C:\Logs\DemoJobsTranscriptOutput.txt' -Append | Out-Null

$VerbosePreference = "continue"
$WarningPreference = "continue"

$jobs = @()

$jobs += Start-Job -ScriptBlock {
$VerbosePreference = "continue"
$WarningPreference = "continue"
"Begin job"
Write-Verbose "Verbose!"
Write-Warning "Warning!"
"End job"
} -Name "Demo"

$jobs | Wait-Job | Out-Null

$jobs | % {
"Result for job '$($_.Name)'"
$_ | Receive-Job -Verbose
}

$jobs | Remove-Job | Out-Null

Stop-Transcript

Expected behavior
------------------------------------------------
The transcript should capture the Verbose and the Warning logs

Actual behavior
-------------------------------------------------
This is the PowerShell output.

VERBOSE: Result for job 'Demo'
Begin job
VERBOSE: Verbose!
WARNING: Warning!
End job
This is the Transcript 'C:\Logs\DemoJobsTranscriptOutput.txt'

**********************
Windows PowerShell transcript start
Start time: 20180110171727
Username: me
RunAs User: me
Machine: (Microsoft Windows NT 10.0.14393.0)
Host Application: C:\WINDOWS\system32\WindowsPowerShell\v1.0\PowerShell_ISE.exe
Process ID: 8600
PSVersion: 5.1.14393.1884
PSEdition: Desktop
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1.14393.1884
BuildVersion: 10.0.14393.1884
CLRVersion: 4.0.30319.42000
WSManStackVersion: 3.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
**********************
VERBOSE: Result for job 'Demo'
Begin job
End job
**********************
Windows PowerShell transcript end
End time: 20180110171727
**********************

Environment data
--------------------------------------
PSVersion 5.1.14393.1884
PSEdition Desktop
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
BuildVersion 10.0.14393.1884
CLRVersion 4.0.30319.42000
WSManStackVersion 3.0
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1

1 vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Alexandre Gaudreault shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    2 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...
      • Phil Hamlin commented  ·   ·  Flag as inappropriate

        I can't solve the issue, but I can offer a workaround.

        Jobs started this way are of type PSRemotingJob, which is a subclass of Job. Here are the properties of that class (we won't need the subclass's specific properties for this explanation).

        https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.job?view=powershellsdk-1.1.0

        Start a new Powershell session and run your script. You'll notice at the end that not only does your Verbose and Warning output not go to the output stream (directing only to the host, so it's displayed in the console and not sent to output and your transcript doesn't record it), but if you dig into the actual object underneath, you'll discover that your job's .Warning and .Verbose properties are empty PSDataCollections - so where are the "Warning!" and "Verbose!" strings coming from in the first place when you run Receive-Job, anyway?

        Now look at your job's .ChildJobs collection. If you poke around in there, you'll discover a child of your job that returns the same output from Receive-Job (including the same annoying redirect and failure to record in transcript), but the child job's .Warning and .Verbose properties actually contain the strings you're after, and you can get them that way - and the transcript will capture them if they're sent from there to Write-Output or Write-Host.

      Feedback and Knowledge Base