TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

PowerShell Redirection Operators

PowerShell Redirection Operators with What is PowerShell, History of PowerShell, Features of PowerShell, PowerShell vs CMD, PowerShell Scripting, PowerShell Versions, PowerShell Commands, PowerShell Looping, PowerShell Conditions, PowerShell Array, PowerShell Brackets etc.

<< Back to POWERSHELL

Redirection Operators

The 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:

Stream Description Introduced in
1 Success Stream PowerShell 2.0
2 Error Stream PowerShell 2.0
3 Warning Stream PowerShell 3.0
4 Verbose Stream PowerShell 3.0
5 Debug Stream PowerShell 3.0
6 Information Stream PowerShell 5.0
* All Streams PowerShell 3.0

PowerShell supports the following redirection operators:

  1. >
  2. >>
  3. >&1

>Operator

This 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 k.txt file.

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

>> Operator

This 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 Operator

This 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





Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf