You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Explains how to redirect output from Windows PowerShell® to text files.
15
12
13
+
Explains how to redirect output from PowerShell to text files.
16
14
17
15
## LONG DESCRIPTION
18
-
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.
19
16
20
-
You can use the following methods to redirect output:
17
+
By default, PowerShell sends its command output to the PowerShell console.
18
+
However, you can direct the output to a text file, and you can redirect error
19
+
output to the regular output stream.
21
20
22
-
- 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.
21
+
You can use the following methods to redirect output:
23
22
24
-
- Use the Tee-Object cmdlet, which sends command output to a text file and then sends it to the pipeline.
23
+
- Use the `Out-File` cmdlet, which sends command output to a text file.
24
+
Typically, you use the `Out-File` cmdlet when you need to use its parameters,
25
+
such as the **Encoding**, **Force**, **Width**, or **NoClobber** parameters.
25
26
26
-
- Use the Windows PowerShell redirection operators.
27
+
- Use the Tee-Object cmdlet, which sends command output to a text file and
28
+
then sends it to the pipeline.
27
29
30
+
- Use the PowerShell redirection operators.
28
31
29
-
### WINDOWS POWERSHELL REDIRECTION OPERATORS
30
-
The redirection operators enable you to send particular types of output to files and to the success output stream.
32
+
### POWERSHELL REDIRECTION OPERATORS
31
33
32
-
The Windows PowerShell redirection operators use the following characters to represent each output type:
34
+
The redirection operators enable you to send particular types of output to
35
+
files and to the success output stream.
33
36
37
+
The PowerShell redirection operators use the following characters to represent
38
+
each output type:
34
39
35
40
```
36
-
* All output
37
-
1 Success output
38
-
2 Errors
39
-
3 Warning messages
40
-
4 Verbose output
41
+
* All output
42
+
1 Success output
43
+
2 Errors
44
+
3 Warning messages
45
+
4 Verbose output
41
46
5 Debug messages
42
47
```
43
48
49
+
NOTE: The All (\*), Warning (3), Verbose (4) and Debug (5) redirection
50
+
operators were introduced in PowerShell 3.0. They do not work in earlier
51
+
versions of PowerShell.
44
52
45
-
NOTE: The All (\*), Warning (3), Verbose (4) and Debug (5) redirection operators were introduced in Windows PowerShell 3.0. They do not work in earlier versions of Windows PowerShell.
53
+
The PowerShell redirection operators are as follows.
46
54
47
-
The Windows PowerShell redirection operators are as follows.
to the specified file. { Get-Process PowerShell, none
115
+
Write-Warning "Test!"
116
+
*>> Appends all output types Write-Verbose "Test Verbose"
117
+
to the contents of the Write-Debug "Test Debug" }
118
+
specified file.
119
+
Test-Output *> Test-Output.txt
120
+
*>&1 Sends all output types Test-Output *>> Test-Output.txt
121
+
(*) to the success Test-Output *>&1
122
+
output stream.
123
+
```
120
124
121
125
The syntax of the redirection operators is as follows:
122
126
123
-
124
127
```
125
128
<input> <operator> [<path>\]<file>
126
129
```
127
130
131
+
If the specified file already exists, the redirection operators that do not
132
+
append data (> and n>) overwrite the current contents of the file without
133
+
warning. However, if the file is a read-only, hidden, or system file, the
134
+
redirection fails. The append redirection operators (>> and n>>) do not write
135
+
to a read-only file, but they append content to a system or hidden file.
128
136
129
-
If the specified file already exists, the redirection operators that do not append data (> and n>) 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 n>>) do not write to a read-only file, but they append content to a system or hidden file.
130
-
131
-
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.
132
-
137
+
To force the redirection of content to a read-only, hidden, or system file,
138
+
use the Out-File cmdlet with its Force parameter. When you are writing to
139
+
files, the redirection operators use Unicode encoding. If the file has a
140
+
different encoding, the output might not be formatted correctly. To redirect
141
+
content to non-Unicode files, use the Out-File cmdlet with its Encoding
0 commit comments