PowerShell Genie

PowerShell Verbose and diagnostic streams

PowerShell separates ordinary data from diagnostic and informational messages by using numbered streams. The success stream is stream 1, errors are stream 2, warnings stream 3, verbose stream 4, debug stream 5, and information stream 6.

Lesson 2 min read Windows PowerShell 5.1 and PowerShell 7

Documentation: Microsoft Learn

Overview

Write-Verbose and Write-Debug are intended for diagnostics and are normally gated by -Verbose and -Debug. Write-Information writes to stream 6 and can carry strings or objects. Since Windows PowerShell 5.0, Write-Host is implemented on the information stream as well, so its messages can be redirected or captured with information-stream redirection. The important distinction is that Write-Host is still not ordinary success-stream output: a function should not use it as the data contract that callers are expected to pipe, filter, sort, or export.

For reusable functions, emit result objects on the success stream and reserve verbose, debug, warning, error, and information messages for commentary about the operation. That gives the caller control over what to display, suppress, redirect, or log.

Inspect this example’s structure

Read the command and its supplied arguments. This example requires real PowerShell or its module; this diagram does not execute it.

function Show-Streams { [CmdletBinding()] param() Write-Output 'Output: the only stream that goes down the pipeline' Write-Verbose 'Verbose: hidden unless -Verbose is passed' Write-Warning 'Warning: shown by default, not part of output' } Show-Streams -Verbose
  1. Stage 1function-Verbose

    An example to inspect

    Preview the example. Sign in for the full lesson and activities.

    function Show-Streams {
        [CmdletBinding()]
        param()
    Write-Output 'Output: the only stream that goes down the pipeline'
    Write-Verbose 'Verbose: hidden unless -Verbose is passed'
    Write-Warning 'Warning: shown by default, not part of output'
    }
    Show-Streams -Verbose

    What happens

    The function writes to three streams. Called with -Verbose, all three appear, and the verbose line is prefixed with VERBOSE: while the warning is prefixed WARNING:. Drop -Verbose and the verbose line vanishes while the other two stay. Only the Write-Output line would survive being assigned to a variable.

    Worth remembering

    • Success-stream objects are the normal pipeline data; diagnostic and informational messages use separate streams.
    • Write-Verbose and Write-Debug are opt-in diagnostics controlled by -Verbose and -Debug.
    • Since Windows PowerShell 5.0, Write-Host uses the information stream and can be redirected or captured separately; it is still not a substitute for returning result objects on stream 1.
    • Design functions so callers can choose independently what data to consume and what diagnostics to display or log.

    Primary documentation

    PowerShell objects and pipelines documentation

    Try it

    Illustrative output · values vary by environment

    1PS> function Show-Streams {
    2PS> [CmdletBinding()]
    3PS> param()
    4PS> Write-Output 'Output: the only stream that goes down the pipeline'
    5PS> Write-Verbose 'Verbose: hidden unless -Verbose is passed'
    6PS> Write-Warning 'Warning: shown by default, not part of output'
    7PS> }
    8PS> Show-Streams -Verbose

    Example reader

    Inspect this page's example

    Fictional browser data when supported

    Run supported commands against the practice data, or inspect the example without executing it.

    Ready to inspect.

      Writes to three different streams so you can see which ones appear.

      Show reference output

      Illustrative output · values vary by environment

      Output: the only stream that goes down the pipeline
      VERBOSE: Verbose: hidden unless -Verbose is passed
      WARNING: Warning: shown by default, not part of output

      Practise this

      Inspect warning diagnostics

      Return Id and Message for Warning-level events.

      Review the lesson

      Keep going

      Next: PowerShell CIM versus WMI

      Check your understanding

      How can you add diagnostic messages without mixing them with report objects?

      Genie guidePowerShell Verbose and diagnostic streams

      PowerShell separates ordinary data from diagnostic and informational messages by using numbered streams. The success stream is stream 1, errors are stream 2, warnings stream 3, verbose stream 4, debug stream 5, and information stream 6.