C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Redirection OperatorsThe Redirection operators are used in PowerShell to redirect the output from the PowerShell console to text files. The following table shows the numbers which are used by the PowerShell redirection operators to represent the available output streams:
PowerShell supports the following redirection operators:
>OperatorThis operator is used to send the specified stream to the specified text file. The following statement is the syntax to use this operator: Command n> Filename Example: PS D:\> Get-childitem > k.txt The above command sends the following output of the Get-childItem cmdlet to the Mode LastWriteTime Length Name ---- ------------- ------ ---- d----- 30-09-2019 05:49 images d----- 09-10-2019 11:14 files d----- 09-10-2019 11:56 powershell d----- 09-10-2019 10:58 users d----- 09-10-2019 04:37 Windows -a---- 05-11-2019 14:53 0 k.txt -a---- 25-06-2018 09:46 2179 powershell.txt >> OperatorThis operator is used to append the specified stream to the specified text file. The following statement is the syntax to use this operator: Command n>> Filename Example: PS D:\> Get-help >> k.txt The above command appends the output of the get-help command to the k.txt file. >&1 OperatorThis operator is used to redirect the specified stream to the success stream. The following statement is the syntax to use this operator: Command n>&1 > Filename Example: PS D:\> &{Write-Error "hello"} 2>&1 > k.txt The above command is used to redirect the following output of Write-Error command to the k.txt file. Write-Error "hello" : hello At line:1 char:1+ &{Write-Error "hello" }2>&1 > D:\k.txt + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException
Next TopicSplit and Join Operators
|