Console output appears out of order in PS v5

Welcome Forums General PowerShell Q&A Console output appears out of order in PS v5

This topic contains 3 replies, has 3 voices, and was last updated by

2 years, 11 months ago.

  • Author
  • #45105

    Topics: 1
    Replies: 1
    Points: 1
    Rank: Member

    Has anyone else seen output display out of order in PowerShell 5?

    C:\Users> Write-Host "Before"; Get-Service e* | select Status, Name, DisplayName; Write-Host "After"
     Status Name        DisplayName
     ------ ----        -----------
    Stopped EapHost     Extensible Authentication Protocol
    Running EFS         Encrypting File System (EFS)
    Running eventlog    Windows Event Log
    Running EventSystem COM+ Event System

    We noticed this after we upgraded to WMF5. It isn't causing any functional problems per se, but it can definitely confuse some people; scripts that uses Write-Host, Write-Verbose etc. to track the flow of the code could produce some surprising results.

    I created a UserVoice bug report with more details (please upvote if you think this needs attention): Bug: Console output appears out of order

  • #45109

    Topics: 3
    Replies: 9
    Points: 3
    Rank: Member

    Try Write-Output instead. Write-Host writes directly to the screen which could cause it to appear before a command that writes to the pipeline (Get-Service), even though it's technically entered after that command.

  • #45111

    Topics: 13
    Replies: 4872
    Points: 1,811
    Helping HandTeam Member
    Rank: Community Hero

    Or, "Never use Write-Host." There are also downsides to putting extraneous stuff into the pipeline, as it can confuse the formatting subsystem.

  • #45120

    Topics: 1
    Replies: 1
    Points: 1
    Rank: Member

    Agreed on not using Write-Host, so let's substitute Write-Verbose – same issue.

    The UserVoice post has more details (including some info added by Tim Curwick about timing changes).

The topic ‘Console output appears out of order in PS v5’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort