Skip to content

Transcription of Write-Information works if preference is 'SilentlyContinue' #6916

@hubuk

Description

@hubuk

Related issue: #4645

run.ps1

Start-Transcript -Path (Join-Path $PSScriptRoot 'transcriptdata.txt')
$InformationPreference = 'SilentlyContinue'
Write-Information 'SilentlyContinue'
$InformationPreference = 'Continue'
Write-Information 'LoudlyContinue'
Stop-Transcript

Steps to reproduce

.\run.ps1

Expected behavior

transcriptdata.txt should contains only LoudlyContinue

Actual behavior

transcriptdata.txt contains only SilentlyContinue

Environment data

> $PSVersionTable
Name                           Value
----                           -----
PSVersion                      6.1.0-preview.1
PSEdition                      Core
GitCommitId                    v6.1.0-preview.1
OS                             Microsoft Windows 10.0.16299
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Investigation

The problem is in if/else statement which starts here:

if ((record.Tags.Contains("PSHOST") && (!record.Tags.Contains("FORWARDED")))
|| (preference == ActionPreference.Continue))

and has a continuation here:
else
{
// Only transcribe informational messages here. Transcription of PSHost-targeted messages is done in the InternalUI.Write* methods.
CBhost.InternalUI.TranscribeResult(StringUtil.Format(InternalHostUserInterfaceStrings.InformationFormatString, record.ToString()));
}

Transcription of Write-Host commands are handled in InternalUI.Write* methods as the comment suggests. These commands are distinguished by "PSHOST" tag.
Transcription of Write-Information commands is supposed to take place in the else statement but code in this statement is being executed only if

(!record.Tags.Contains("PSHOST") || record.Tags.Contains("FORWARDED"))
&&
preference != ActionPreference.Continue)

This condition is invalid. Correct condition is:

!record.Tags.Contains("PSHOST")
&&
preference == ActionPreference.Continue)

PR pending...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-Discussionthe issue may not have a clear classification yet. The issue may generate an RFC or may be reclassifResolution-FixedThe issue is fixed.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