Redirection operators
Chapter 3, Working with Objects in PowerShell, started exploring the different output streams PowerShell utilizes.Information from a command may be redirected using the redirection operator, >
. Information may be sent to another stream or a file.For example, the output from a command can be directed to a file. The file contains the output as it would have been displayed in the console:
PS> Get-Process -Id $pid > process.txt
PS> Get-Content process.txt
NPM(K) PM(M) WS(M) CPU(s) Id SI ProcessName
------ ----- ----- ------ -- -- -----------
78 144.69 186.91 12.69 15284 1 pwsh
Each of the streams in PowerShell has a number associated with it. These are shown in the following table:
Stream name | Stream number |
Standard out | 1 |
Error | 2 |
Warning | 3 |
Verbose | 4 |
Debug | 5 |
Information | 6 |
Each of the preceding streams can be redirected. In most cases, PowerShell provides...