question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Write-Information results in InformationRecord being added to the Information stream unexpectedly in some cases

See original GitHub issue

Steps to reproduce

First run this in a new PowerShell session with -noprofile:

Write-Information 'Information'
Write-Verbose 'Verbose'
Write-Debug 'Debug'

Note how none of those produce any output, because each of their corresponding $*Preference variables is set to [System.Management.Automation.ActionPreference]::SilentlyContinue by default.

Now run this in the same session:

$ps = [powershell]::Create()
$ps.AddScript(@'
Write-Information 'Information'
Write-Verbose 'Verbose'
Write-Debug 'Debug'
'@).Invoke()
$ps.Streams.Verbose # Empty, as expected
$ps.Streams.Debug # Empty, as expected
$ps.Streams.Information # Not empty, and outputs "Information"...why?

Expected behavior

Both blocks of code would not output anything.

Actual behavior

The second block outputs the following text:

Information

Environment data

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

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:2
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
mklement0commented, Sep 15, 2020

@vexx32, the transcript behavior with respect to Write-Information has been fixed (after all, a transcript should not show different output than the console), though I’m not sure in what version exactly, and I’m not aware of an associated bug report (still affects Windows PowerShell; see also: #4645).

Let me try to summarize the troubling inconsistency (derived from observation, not source-code analysis):

  • Unlike with all other streams, SilentlyContinue for stream 6 (Write-Information) does not suppress writing to the stream at the source.

  • Seemingly, it is unexpectedly left to the host to enforce the silence for display.

This is easy to demonstrate: a redirection of stream 6 succeeds even with -InformationAction SilentlyContinue:

PS> Write-Information info -Infa SilentlyContinue 6>&1 | % { "[$_]" }
[info]  # !! stream output was still produced and redirected to the success stream.

To contrast this with the behavior of the Write-* cmdlets for the other streams:

'Write-Error', 'Write-Warning', 'Write-Verbose', 'Write-Debug', 'Write-Information' | % {
  $stream = ($_ -split '-')[-1]
  $htArgs = if ($stream -in 'Debug', 'Verbose') { # Boolean common parameters
    @{
      $stream = $false
    }
  } else { # enum-based common parameters
    @{
      ($stream + 'Action') = 'SilentlyContinue'
    }
  }
  $out = & $_ @htArgs $stream *>&1
  "redirected $stream`: [$out]"
}
redirected Error: []
redirected Warning: []
redirected Verbose: []
redirected Debug: []
redirected Information: [Information]
1reaction
KirkMunrocommented, Sep 15, 2020

I suppose, why be consistent, right? Just because the error, warning, verbose, debug and progress streams can be silenced using System.Management.Automation.ActionPreference.SilentlyContinue, why should the information stream work the same way? That would make too much sense. 🙄

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to process Write-Information pipeline output when ...
Unlike SilentlyContinue , Ignore completely forgets the informational message; it doesn't add the informational message to the information ...
Read more >
Write-Information (Microsoft.PowerShell.Utility)
Write-Information lets you add an informational message to the stream, and specify how PowerShell handles information stream data for a command.
Read more >
How to run PowerShell Core scripts from .NET Core applications
In this article we will jump forward to take a look at runspace execution for PowerShell Core and .NET Core applications. Including topics...
Read more >
Write-Information - PowerShell Command - PDQ
Write-Information lets you add an informational message to the stream, and specify how Windows PowerShell handles information stream data for a command. The...
Read more >
Remedy & ITSM Error Message Lookup - ARE|RRR - rrr.se
Level Number Subject NOTE 32 AR System server terminated normally. ARERR 49 Internal error: The request ID is invalid. WARNING 50 You have no permission to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found