PowerShell Redirection Operators
In this tutorial we will go through PowerShell Redirection Operators. PowerShell by default sends the output of the commands, warnings and errors in the console. You are able to send those outputs to files in order to store them. There are different ways to redirect the output to files:
- Out-File
- Tee-Object
- Set-Content
- Add-Content
- Redirection Operators
We will not go though the commands in this tutorial. We will only check the redirection operators.
PowerShell redirection operators are using specific characters to specify the output to files Please check the list below:
*
– All output1
– Success output2
– Errors3
– Warnings messages4
– Verbose Output5
– Debug messages6
– Informational messages
In order to use *
, 3
, 4
, 5
you need to have PowerShell 3.0 or above. Those four types were introduced in Powershell 3.0. The newer type that has been introduced in PowerShell 5.0 is 6
. You need to have PowerShell 5.0 or above in order to used it.
Now we will go through the list of the redirection operators and see some examples.
[adinserter name=”In Article”]
Redirection Operators
>
– Sends output to the specified file>>
– Appends output to the content of the specified file2>
– Sends errors to the specified file.2>>
– Appends errors to the content of the specified file2>&1
– Sends errors and success output to the success output stream3>
– Sends warnings to the specified file3>>
– Appends warnings to the contents of the specified file.3>&1
– Sends warnings and success output to the success output stream4>
– Sends verbose output to the specified file4>>
– Appends verbose output to the contents of the specified file4>&1
– Sends verbose output and success output to the success output stream5>
– Sends debug messages to the specified file5>>
– Appends debug messages to the contents of the specified file5>&1
– Sends debug messages and success output to the success output stream6>
– Sends informational messages to a specified file6>>
– Appends informational messages to the contents of a specified file6>&1
– Sends informational messages and success output to the success output stream.*>
– Sends all output types to the specified file*>>
– Appends all output types to the contents of the specified file*>&1
– Sends all output types to the success output stream
Example 1
Code:
Get-NetAdapter > C:\Scripts_Output\NetAdapters.txt
After you will run the command above, the output of the command will be redirected to the file specified. Below is the content of the file.
Then I run the next command and all the content as you can see at the below output, has been replaced.
Code:
Get-NetAdapter -IncludeHidden > C:\Scripts_Output\NetAdapters.txt
Output:
[adinserter name=”In Article”]
Example 2:
In this example, we will use the same command and redirect the out put to the same file. The difference in this example is that I have changed the redirection operator. I am using >>
as redirection operator and the result is to append the second command to the content of the file and not replace it as example 1.
Code:
Get-NetAdapter > C:\Scripts_Output\NetAdapters.txt Get-NetAdapter -IncludeHidden >> C:\Scripts_Output\NetAdapters.txt
Output:
I have used only the first two redirection operators in my examples to help you understand the difference. I will not go through the full list of redirection operators as this will make the tutorial really long. The best way is to try and play with them in order to understand exactly what each operator is doing.
I hope the tutorial about PowerShell Redirection Operators is helpful.
Please let me know your comments and thoughts.
You feedback is appreciated.
[adinserter name=”In Article”]
Related Links:
- PowerShell Tutorials
- PowerShell Scripts
- about_Redirection | Microsoft Docs
- Out-File – Microsoft Docs
- Tee-Object – Microsoft Docs
- Set-Content – Microsoft Docs
- Add-Content – Microsoft Docs
[adinserter name=”Matched-Content”]


Looks like you left out stream #6, the Information stream (added in 5.0)
Hi Mike,
Thank you for the notice. I have updated the post and included stream #6 also.
Thanks
Stephanos