13 Using all the streams

 

You may need to flip back a few chapters and refamiliarize yourself with the [CmdletBinding()] keyword. We can add this to a Param() block, which turns our function into an advanced function that enables the commands for verbose, warning, informational, and other output. Well, it’s time to put that to use and demonstrate why you’d want to use them.

13.1 Knowing the seven output streams

It’s helpful to understand that PowerShell has seven output streams rather than the one we normally think of. First up, and the one you’re most familiar with, is the Success stream, which you’re used to thinking of as “the end of the pipeline.” This gets some special treatment from the PowerShell engine. For example, it’s the pipeline used to pass objects from command to command. Additionally, at the end of the pipeline, PowerShell sort of invisibly adds the Out-Default cmdlet, which runs any objects in the pipeline through PowerShell’s formatting system. Whatever hosting application you’re using—the PowerShell console, Visual Studio Code (VS Code), and so on—is responsible for dealing with that output by placing it onto the screen or doing something else.

There are seven streams in all:

  1. Success, which we just discussed
  2. Error
  3. Warning
  4. Verbose
  5. Debug
  6. Information
  7. Progress

Those numbers correspond with how PowerShell references each pipeline for redirection purposes.

13.2 Adding verbose and warning output

13.3 Doing more with -Verbose

13.4 Information output

13.4.1 A detailed Information stream example

13.5 Your turn