Start/Stop-Transcript does not always capture all output written to the PowerShell console.
When calling a Cmdlet that uses WriteObject to output data, there appears to be a delay that backs up the output pipeline. This results in the output to not be captured when Stop-Transcript is called. Test-TranscriptIssue.cs is an example of such Cmdlet.
Given the script below (You can easily execute this by launching the project file from this repo in Visual Studio)
Start-Transcript -Path transcript.txt -UseMinimalHeader
Write-Output "Hello from Write-Output"
Write-Host "Hello from Write-Host"
Test-TranscriptIssue
Write-Output "Goodbye from Write-Output"
Write-Host "Goodbye from Write-Host"
Stop-Transcript
# Write out the transcript to the console
cat ./transcript.txt
There are two interesting observations here:
Goodbye from Write-Output
is appearing before the output ofTest-TranscriptIssue
. IsTest-TranscriptIssue
introducing a delay to the output pipeline?- The output of
Test-Transcript
andGoodbye from Write-Output
is missing from the transcript.
- We were only able to reproduce this with Cmdlets that use WriteObject (as seen in Test-TranscriptIssue.cs). If we replace
Test-TranscriptIssue
withGet-Module
in the script, everthing seems to work as expected. - It feels like WriteObject is introducing a delay to the output pipeline that is causing Stop-Transcript to write to file before it is finished processing.
- Is WriteObject the right thing to be using in Cmdlets?