Please feel free to provide feedback or file bugs here.

No StdOut output on console until second object

Let me explain. I have a script that is collecting data, and I send it to StdOut by simply piping it into Select (but problem also happens if I add a ForEach loop and simply make [PSCustomObject] objects). Then my script loops to the next server. That output is not displaying on the screen. All is not lost though, when the script loops to the second server and displays both the first and second will now display. When the third server finishes it displays OK, as does the 4th.

So it looks like it's just the first one. Normally I would be OK with this, except that if the name of the second server is inputted wrong, my script will abort and the data from the first server disappears forever.

Has anyone else noted this behavior? I don't remember this happening before 5.1 and I have had multiple people able to reproduce this issue.

4 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)

    We’ll send you updates on this idea

    Martin PughMartin Pugh shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    3 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Martin PughMartin Pugh commented  ·   ·  Flag as inappropriate

        To demonstrate why it's a big problem:

        1..5 | % { [PSCustomObject]@{
        Name = "First$_"
        Number = $_
        }}

        Start-Sleep -Seconds 5
        write-error "testing" -ErrorAction Stop

        6..10 | % { [PSCustomObject]@{
        Name = "Second$_"
        Number = $_
        }}

        If you run this, you'll notice that the script exits with an error properly, but the 1..5 data is never outputted.

      • Martin PughMartin Pugh commented  ·   ·  Flag as inappropriate

        Sure Joey:

        1..5 | % { [PSCustomObject]@{
        Name = "First$_"
        Number = $_
        }}

        Start-Sleep -Seconds 5

        6..10 | % { [PSCustomObject]@{
        Name = "Second$_"
        Number = $_
        }}

        $PSVersionTable

        Name Value
        ---- -----
        PSVersion 5.1.14394.1000
        PSEdition Desktop
        PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
        BuildVersion 10.0.14394.1000
        CLRVersion 4.0.30319.42000
        WSManStackVersion 3.0
        PSRemotingProtocolVersion 2.3
        SerializationVersion 1.1.0.1

      • Wesley HartmanWesley Hartman commented  ·   ·  Flag as inappropriate

        A small script to demonstrate this:

        foreach( $i in (0..4) ){
        Start-Sleep -Seconds 5
        Get-ChildItem |
        Select-Object -First 1 -Skip $i -Property Name, LastWriteTime
        }

        Output of $PSVersionTable:

        Name Value
        ---- -----
        PSVersion 5.1.14393.206
        PSEdition Desktop
        PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
        BuildVersion 10.0.14393.206
        CLRVersion 4.0.30319.42000
        WSManStackVersion 3.0
        PSRemotingProtocolVersion 2.3
        SerializationVersion 1.1.0.1

      Feedback and Knowledge Base