Start/Stop-Transcript does not capture everything written to the console · Issue #10994 · PowerShell/PowerShell · GitHub
Skip to content

Start/Stop-Transcript does not capture everything written to the console #10994

Open

Description

@zammitt

Start/Stop-Transcript does not always capture everything written to the console.

I created a github repo with code, repro steps and more context: https://github.com/zammitt/PowerShellTranscriptIssue

Steps to reproduce

In a script file (.ps1)

  1. Start-Transcript
  2. Run a Cmdlet that outputs data with WriteObject
  3. Stop-Transcript
  4. Observe that the output was not written to the transcript

Here is a script to repro:

Install-Module TranscriptIssue
Import-Module TranscriptIssue

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

The code for Test-TranscriptIssue can be found here: https://github.com/zammitt/PowerShellTranscriptIssue/blob/master/TestIssueOnPowerShellCore/Test-TranscriptIssue.cs

Expected behavior

The contents of the transcript match what was written to the console while the transcript was active.

Transcript started, output file is transcript.txt
Hello from Write-Output
Hello from Write-Host

Goodbye from Write-Host
TestProperty
------------
TestValue
Goodbye from Write-Output
Transcript stopped, output file is D:\code\PowerShellTranscriptIssue\TestIssueOnPowerShellCore\bin\Debug\netcoreapp3.0\transcript.txt
**********************
PowerShell transcript start
Start time: 20191105180138
**********************
Hello from Write-Output
Hello from Write-Host

Goodbye from Write-Host
TestProperty
------------
TestValue
Goodbye from Write-Output
**********************
PowerShell transcript end
End time: 20191105180138
**********************

Actual behavior

The transcript is missing data that was written to the console while the transcript was active.

Transcript started, output file is transcript.txt
Hello from Write-Output
Hello from Write-Host

Goodbye from Write-Host
TestProperty
------------
TestValue
Goodbye from Write-Output
Transcript stopped, output file is D:\code\PowerShellTranscriptIssue\TestIssueOnPowerShellCore\bin\Debug\netcoreapp3.0\transcript.txt
**********************
PowerShell transcript start
Start time: 20191105180138
**********************
Transcript started, output file is transcript.txt
Hello from Write-Output
Hello from Write-Host

Goodbye from Write-Host
**********************
PowerShell transcript end
End time: 20191105180138
**********************

Environment data

Name                           Value
----                           -----
PSVersion                      6.2.3
PSEdition                      Core
GitCommitId                    6.2.3
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Activity

  1. added
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Nov 5, 2019
  2. JamesWTruher commented on Nov 6, 2019

    @JamesWTruher
    Collaborator

    TLDR:

    • Mixing and matching objects, strings, and write-host with transcription is really tricky.

    I’m not sure this is a bug, per se, but a subtle interaction between the script and how transcription works with our pipelines. I will agree that it is in no way intuitive.

    One of the things that happen when you emit objects is that the formatting of those objects gets handled by out-default, but after the script has completed and since transcription has stopped, that output doesn’t get transcribed. Strings are handled differently, they’re sometimes short-circuited through formatting (but sometimes not). The combination of write-host (which makes an immediate write), write-object (which may get short-circuited through formatting), and output of a makes this pretty hard to reason about what’s going to happen. However, there may be a way that you may want to try (See “A POSSIBLE WAY” below).

    Even more details:

    Here are a couple of variations on the theme:

    Variation 1 – your scenario, with the output of a structured object at the end of all of the other operations.

    PS> cat s2.ps1
    remove-item s2 -ea ignore
    start-transcript s2 -usemin
    write-host "1"
    write-output "2"
    get-location
    write-host "4"
    write-output "5"
    stop-transcript
     
    PS> ./s2.ps1
    Transcript started, output file is s2
    1
    2
     
    4
    Path
    ----
    /Users/jimtru/src/projects/transcript
    5
    Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s2

    This one is really confusing, but explainable (but perhaps not satisfying). ‘Write-Host 4’ is visible before get-location because Write-Host is hot-rodded directly into the host and emitted (there’s code in transcription which essentially tees the output to the transcript file and the console). Then we have the regular output of get-location and write-output 5 sent as output of the script.

    Since transcription is turned off before the script exits, it’s not rendered in the transcript, because the objects were sent to the next consumer in the pipeline (in this case, it’s out-default which is what the engine does automatically). The tricky bit is that strings are also somewhat hot-rodded in our formatting, so the first write-output 2 gets emitted and captured by the transcript, but the insertion of the get-location object causes it to be pushed into the stack of things that need actual formatting, which sets a bit of state for any remaining objects which may need formatting (which is why the second write-output 5 doesn’t get transcripted.

    **********************
    PowerShell transcript start
    Start time: 20191106114858
    **********************
    Transcript started, output file is s2
    1
    2
    
    4
    **********************
    PowerShell transcript end
    End time: 20191106114858
    **********************

    Variation 2 – move the object emission to the beginning

    start-transcript s3 -usemin
    get-location
    write-host "1"
    write-output "2"
    write-host "4"
    write-output "5"
    stop-transcript

    We can see that the write-host happen before anything, and then the objects start to come out. The string output essentially forces the object to be rendered to the screen, but you’ll notice that the transcript contains only the output of Write-Host. That’s because those were piped to the formatting after the script turned off transcription.

    PS> ./s3.ps1
    Transcript started, output file is s3
     
    1
    4
    Path
    ----
    /Users/jimtru/src/projects/transcript
    2
    5
    Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s3
     
      
    PS> cat s3
     
    **********************
    PowerShell transcript start
    Start time: 20191106115142
    **********************
    Transcript started, output file is s3
     
    1
    4
    **********************
    PowerShell transcript end
    End time: 20191106115142
    **********************

    Variation 3 – object emission at the end:
    We can see that everything but the object is now in the transcript

    PS> cat s4.ps1
    start-transcript s4 -usemin
    write-host "1"
    write-output "2"
    write-host "4"
    write-output "5"
    get-location
    stop-transcript

    Here’s the execution flow

    PS> ./s4.ps1
    Transcript started, output file is s4
    1
    2
    4
    5
     
    Path
    ----
    /Users/jimtru/src/projects/transcript
    Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s4

    And the content of the transcript

    **********************
    PowerShell transcript start
    Start time: 20191106115255
    **********************
    Transcript started, output file is s4
    1
    2
    4
    5
     
    **********************
    PowerShell transcript end
    End time: 20191106115255
    **********************

    A Possible Way

    Lastly, here’s a slight variation on the original, but now everything will be in the transcript. I’ve taken the code of interest and am calling the formatter forcefully via out-default. You’ll notice that the last Write-Host call is still out of order, that’s because of the short-circuiting of write-host which is a direct call into the host and does not go into the output stream.

    start-transcript s5 -usemin
    .{
        write-host "1"
        write-output "2"
        get-location
        write-host "4"
        write-output "5"
    } | out-default
    stop-transcript

    Here’s the execution, followed by the transcript

    PS> ./s5.ps1
    Transcript started, output file is s5
    1
    2
     
    4
    Path
    ----
    /Users/jimtru/src/projects/transcript
    5
     
    Transcript stopped, output file is /Users/jimtru/src/projects/transcript/s5
      
     
    PS> cat s5
    **********************
    PowerShell transcript start
    Start time: 20191106115701
    **********************
    Transcript started, output file is s5
    1
    2
     
    4
    Path
    ----
    /Users/jimtru/src/projects/transcript
    5
     
    **********************
    PowerShell transcript end
    End time: 20191106115701
    **********************
  3. he852100 commented on Nov 7, 2019

    @he852100

    I suggest adding a new option. Allows it to output color documents

  4. zammitt commented on Nov 8, 2019

    @zammitt
    Author

    James Truher (@JamesWTruher) Thank you for the detailed reply. Out-Default works great! I ended up using the -Transcript flag so that the objects are still passed forward on the pipeline.

    he852100 I'll second this. Color in transcripts would be awesome.

  5. vexx32 commented on Nov 8, 2019

    @vexx32
    Collaborator

    My one question to that is always going to be -- how? PS works with text files, not formatted documents. The next step up would perhaps be Markdown, which would be messier to read in the console, and still doesn't natively support color formatting. That should probably be a whole other issue discussion, though. 😉

  6. SteveL-MSFT commented on Jan 8, 2020

    @SteveL-MSFT
    Member

    @PowerShell/powershell-committee reviewed this, we believe a complete solution for transcription (like the unix script command) would love to see the community build a new cmdlet (published to PSGallery) that uses ptty or on Windows grabbing the screen buffer, but the ask is out of scope for the current transcription framework.

  7. added
    Committee-ReviewedPS-Committee has reviewed this and made a decision
    and removed
    Review - CommitteeThe PR/Issue needs a review from the PowerShell Committee
    on Jan 8, 2020
  8. added
    Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributors
    Issue-Enhancementthe issue is more of a feature request than a bug
    and removed
    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get a
    on Jan 31, 2020
  9. Cloudmersive commented on Mar 7, 2020

    @Cloudmersive

    Dear Microsoft - when are you going to fix this? Steve Lee (@SteveL-MSFT) this is critical functionality - how is it "out of scope"? It is critically important that bedrock Microsoft capabilities actually solve problems at scale and this is a huge gap

  10. mklement0 commented on Mar 7, 2020

    @mklement0
    Contributor

    To complete the picture of the current problems and limitations:

    On Unix-like platforms, use of the script utility already is an option to bypass all these issues (albeit not from within a script), while additionally providing:

    • capturing of VT sequences (ANSI escapes)
    • capturing of interactive prompt strings and what the user typed

    However, the PSReadLine module doesn't play nice with the latter in Read-Host calls; e.g. (on Linux):

    # Transcribe an interactive PowerShell user prompt.
    # Save the transcript in file .\typescript
    script -c 'pwsh -nop -c "read-host prompt"'

    If you type abc when prompted, the transcript won't contain just string abc, but the equivalent following, which makes the terminal go haywire when you cat the resulting file; note how each letter typed caused the inclusion of VT sequences and reprinting of all letters typed so far:

    `e[?1h`e=prompt:·`e[6na`e[62;9Hab`e[62;9Habc
    
  11. sba923 commented on Dec 4, 2020

    @sba923
    Contributor

    Just discovered that Start-Transcript typically captures little to no output from ROBOCOPY.

    image

    image

    image

    PSTranscriptAndRobocopy.zip

    Would there be a workaround?

  12. 30 remaining items

  13. arakielG commented on Mar 22, 2025

    @arakielG

    Just to add my voice to this still being an issue. I have an install script that runs a bunch of winget commands. Start-Transcript captures the first half dozen or so and then after that the only thing getting transcribed is the Write-Hosts I have between them all

    `Installing EdgeView2Runtime...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing Google Drive...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing Google Chrome...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing BitWarden...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing Git...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing GitLFS...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing GitHub Desktop...
    Found an existing package already installed. Trying to upgrade the installed package...
    No available upgrade found.
    No newer package versions are available from the configured sources.
    Installing UnityHub...

    Installing JetBrains Rider...

    Installing VSCodium...

    Installing Windows Terminal...

    Installing Powershell...

    Installing WSL...

    Installing Ubuntu...

    ` ... etc

  14. A9G-Data-Droid commented on Jun 2, 2025

    @A9G-Data-Droid

    The response from Microsoft here has been really surprising. At the very least, Stop-Transcript should call for a flush and wait for flush of anything at the point when stop is called. As for it's inability to capture all output, that is certainly a bug and it's absurd to say it's not. There should be no workaround or call upon the community. This feature doesn't do what it says on the tin. Is it supported or not?

  15. sba923 commented on Jun 12, 2025

    @sba923
    Contributor

    IMVHO a broken transcript feature is about as useful as no transcript feature.

    So, this must be fixed, or removed/deprecated.

  16. microsoft-github-policy-service commented on Dec 10, 2025

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  17. jkmartindale commented on Dec 10, 2025

    @jkmartindale

    still a footgun, bot bro

  18. DennisL68 commented on Dec 10, 2025

    @DennisL68

    Just because no one is working actively on this issue doesn't mean that a solution isn't in high demand.

  19. lonbluster commented on Dec 31, 2025

    @lonbluster

    broken on Windows 2019, no output generated in transcript file
    PSVersion 5.1.17763.8146

  20. microsoft-github-policy-service commented on Jun 30, 2026

    @microsoft-github-policy-service
    Contributor

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

  21. jkmartindale commented on Jun 30, 2026

    @jkmartindale

    This issue has not had any activity in 6 months, if there is no further activity in 7 days, the issue will be closed automatically.

    Activity in this case refers only to comments on the issue. If the issue is closed and you are the author, you can re-open the issue using the button below. Please add more information to be considered during retriage. If you are not the author but the issue is impacting you after it has been closed, please submit a new issue with updated details and a link to this issue and the original.

    Bump

  22. EclipsedStar0 commented on Jul 26, 2026

    @EclipsedStar0

    Powershell transcription is completely missing over half the console output of running a python file printing to console... and they are all strings. Which was said to be done correctly. No it ain't. This is broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Committee-ReviewedPS-Committee has reviewed this and made a decisionIssue-Enhancementthe issue is more of a feature request than a bugWG-Cmdletsgeneral cmdlet issues

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions