You are on page 1of 2

TOPIC about_Redirection SHORT DESCRIPTION Describes how to redirect output from Windows PowerShell to text files.

LONG DESCRIPTION By default, Windows PowerShell sends its command output to the Windows PowerShell console. However, you can direct the output to a text file, and you can redirect error output to the regular output stream. You can use the following methods to redirect output: - Use the Out-File cmdlet, which sends command output to a text file. Typically, you use the Out-File cmdlet when you need to use its parameters, such as the Encoding, Force, Width, or NoClobber parameters. - Use the Tee-Object cmdlet, which sends command output to a text file and then sends it to the pipeline. - Use the Windows PowerShell redirection operators. The Windows PowerShell redirection operators are as follows. Operator Description -------- ---------------------> Sends output to the specified file. >> Appends the output to the contents of the specified file. Sends errors to the specified file. Appends the errors to the contents of the specified file. Sends errors to the success output stream. Example -----------------------------get-process > process.txt dir *.ps1 >> scripts.txt

2> 2>>

get-process none 2> errors.txt get-process none 2>> save-errors.txt

2>&1

get-process none, powershell 2>&1

The syntax of the redirection operators is as follows: <input> <operator> [<path>\]<file> If the specified file already exists, the redirection operators that do not append data (> and 2>) overwrite the current contents of the file without warning. However, if the file is a read-only, hidden, or system file, the redirection fails. The append redirection operators (>> and 2>>) do not write to a read-only file, but they append content to a system or hidden file.

To force the redirection of content to a read-only, hidden, or system file, use the Out-File cmdlet with its Force parameter. When you are writing to files, the redirection operators use Unicode encoding. If the file has a different encoding, the output might not be formatted correctly. To redirect content to non-Unicode files, use the Out-File cmdlet with its Encoding parameter. SEE ALSO Out-File Tee-Object about_Operators about_Command_Syntax about_Path_Syntax

You might also like