Skip to content

Is there a way to capture interleaved output and PSDataStreams from a PowerShell instance? #7477

@alx9r

Description

@alx9r

The output and PSDataStreams are available individually from a PowerShell instance. These individual streams, however, do not seem to contain enough information to determine order of an item in one stream compared with an item in another stream.

Steps to reproduce

$ErrorActionPreference = 'Continue'
$powershell = [powershell]::Create().AddScript({
    $VerbosePreference = 'Continue'
    'output1'
    Write-Verbose 'verbose1'
    Write-Error 'error1'
    Write-Error 'error2'
    Write-Verbose 'verbose2'
    'output2'
})

$powershell.Invoke()
$powershell.Streams.Verbose
$powershell.Streams.Error

Behavior I'm looking for

output1
verbose1
    $VerbosePreference = 'Continue'
    'output1'
    Write-Verbose 'verbose1'
    Write-Error 'error1'
    Write-Error 'error2'
    Write-Verbose 'verbose2'
    'output2'
 : error1
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

    $VerbosePreference = 'Continue'
    'output1'
    Write-Verbose 'verbose1'
    Write-Error 'error1'
    Write-Error 'error2'
    Write-Verbose 'verbose2'
    'output2'
 : error2
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
verbose2
output2

Actual behavior

output1
output2
verbose1
verbose2
    $VerbosePreference = 'Continue'
    'output1'
    Write-Verbose 'verbose1'
    Write-Error 'error1'
    Write-Error 'error2'
    Write-Verbose 'verbose2'
    'output2'
 : error1
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

    $VerbosePreference = 'Continue'
    'output1'
    Write-Verbose 'verbose1'
    Write-Error 'error1'
    Write-Error 'error2'
    Write-Verbose 'verbose2'
    'output2'
 : error2
+ CategoryInfo          : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException

Environment data

> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0-preview.4
PSEdition                      Core
GitCommitId                    6.1.0-preview.4
OS                             Microsoft Windows 6.3.9600 
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Questionideally support can be provided via other mechanisms, but sometimes folks do open an issue to get aResolution-AnsweredThe question is answered.WG-Enginecore PowerShell engine, interpreter, and runtime

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions