Book Image

Getting Started with Powershell

Book Image

Getting Started with Powershell

Overview of this book

Table of Contents (19 chapters)
Getting Started with PowerShell
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Next Steps
Index

PowerShell streams and redirection


We've talked about the output stream, but it turns out that PowerShell has quite a few streams besides this. Here's the list, including one that was introduced in PowerShell 5:

Stream

Number

Contents

Output

1

Output from commands

Error

2

Error messages

Warning

3

Warning messages

Debug

4

Debug messages

Verbose

5

Verbose output

Information

6

General information (PowerShell 5)

Similar to DOS, you can redirect streams to a file using the greater-than symbol (>). For example, you can send a directory listing to a file as follows:

Dir c:\temp >c:\temp\files.txt

The output is formatted according to standard PowerShell formatting, but since it's just a text file, you can't recreate the objects that you started with. Also, unlike with Set-Content, you can't control the output encoding, which is always Unicode if you use the redirection operator.

Other types of redirection operators

In addition to the single greater-than symbol, there are...