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 ...
Get Getting Started with PowerShell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.