2
2
external help file : Microsoft.PowerShell.Commands.Utility.dll-Help.xml
3
3
Locale : en-US
4
4
Module Name : Microsoft.PowerShell.Utility
5
- ms.date : 12/12/2022
5
+ ms.date : 07/27/2023
6
6
online version : https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.2&WT.mc_id=ps-gethelp
7
7
schema : 2.0.0
8
8
title : Out-File
@@ -95,15 +95,15 @@ Out-File -FilePath .\Process.txt -InputObject $Procs -Encoding ASCII -Width 50
95
95
```
96
96
97
97
The ` Get-Process ` cmdlet gets the list of processes running on the local computer. The ** Process**
98
- objects are stored in the variable, ` $Procs ` . ` Out-File ` uses the ** FilePath** parameter and creates
99
- a file in the current directory named ** Process.txt** . The ** InputObject** parameter passes the
100
- process objects in ` $Procs ` to the file ** Process.txt** . The ** Encoding** parameter converts the
101
- output to ** ASCII** format. The ** Width** parameter limits each line in the file to 50 characters so
102
- some data might be truncated.
98
+ objects are stored in the variable, ` $Procs ` . ` Out-File ` uses the ** FilePath** parameter and
99
+ creates a file in the current directory named ** Process.txt** . The ** InputObject** parameter passes
100
+ the process objects in ` $Procs ` to the file ** Process.txt** . The ** Encoding** parameter converts
101
+ the output to ** ASCII** format. The ** Width** parameter limits each line in the file to 50
102
+ characters so some data might be truncated.
103
103
104
104
### Example 4: Use a provider and send output to a file
105
105
106
- This example shows how to use the ` Out-File ` cmdlet when you are not in a ** FileSystem** provider
106
+ This example shows how to use the ` Out-File ` cmdlet when you aren't in a ** FileSystem** provider
107
107
drive. Use the ` Get-PSProvider ` cmdlet to view the providers on your local computer. For more
108
108
information, see [ about_Providers] ( ../Microsoft.Powershell.Core/About/about_Providers.md ) .
109
109
@@ -132,8 +132,8 @@ The `Set-Location` command uses the **Path** parameter to set the current locati
132
132
provider ` Alias: ` . The ` Get-Location ` cmdlet displays the complete path for ` Alias: ` .
133
133
` Get-ChildItem ` sends objects down the pipeline to the ` Out-File ` cmdlet. ` Out-File ` uses the
134
134
** FilePath** parameter to specify the complete path and filename for the output,
135
- ** C:\TestDir\AliasNames.txt** . The ` Get-Content ` cmdlet uses the ** Path** parameter and displays the
136
- file's content in the PowerShell console.
135
+ ** C:\TestDir\AliasNames.txt** . The ` Get-Content ` cmdlet uses the ** Path** parameter and displays
136
+ the file's content in the PowerShell console.
137
137
138
138
### Example 5: Set file output width for entire scope
139
139
@@ -151,7 +151,9 @@ function DemoDefaultOutFileWidth() {
151
151
152
152
Get-ChildItem Env:\ > $logFile
153
153
154
- Get-Service -ErrorAction Ignore | Format-Table -AutoSize | Out-File $logFile -Append
154
+ Get-Service -ErrorAction Ignore |
155
+ Format-Table -AutoSize |
156
+ Out-File $logFile -Append
155
157
156
158
Get-Process | Format-Table Id,SI,Name,Path,MainWindowTitle >> $logFile
157
159
}
@@ -201,8 +203,8 @@ The acceptable values for this parameter are as follows:
201
203
- `utf8NoBOM` : Encodes in UTF-8 format without Byte Order Mark (BOM)
202
204
- `utf32` : Encodes in UTF-32 format.
203
205
204
- Beginning with PowerShell 6.2, the **Encoding** parameter also allows numeric IDs of registered code
205
- pages (like `-Encoding 1251`) or string names of registered code pages (like
206
+ Beginning with PowerShell 6.2, the **Encoding** parameter also allows numeric IDs of registered
207
+ code pages (like `-Encoding 1251`) or string names of registered code pages (like
206
208
` -Encoding "windows-1251"` ). For more information, see the .NET documentation for
207
209
[Encoding.CodePage](/dotnet/api/system.text.encoding.codepage?view=netcore-2.2).
208
210
@@ -241,8 +243,8 @@ Accept wildcard characters: False
241
243
242
244
# ## -Force
243
245
244
- Overrides the read-only attribute and overwrites an existing read-only file. The **Force** parameter
245
- does not override security restrictions.
246
+ Overrides the read-only attribute and overwrites an existing read-only file. The **Force**
247
+ parameter doesn't override security restrictions.
246
248
247
249
` ` ` yaml
248
250
Type: System.Management.Automation.SwitchParameter
@@ -275,10 +277,11 @@ Accept wildcard characters: False
275
277
276
278
# ## -LiteralPath
277
279
278
- Specifies the path to the output file. The **LiteralPath** parameter is used exactly as it is typed.
279
- Wildcard characters are not accepted. If the path includes escape characters, enclose it in single
280
+ Specifies the path to the output file. The **LiteralPath** parameter is used exactly as it's typed.
281
+ Wildcard characters aren't accepted. If the path includes escape characters, enclose it in single
280
282
quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape
281
- sequences. For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
283
+ sequences. For more information, see
284
+ [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
282
285
283
286
` ` ` yaml
284
287
Type: System.String
@@ -312,7 +315,7 @@ Accept wildcard characters: False
312
315
313
316
# ## -NoNewline
314
317
315
- Specifies that the content written to the file does not end with a newline character. The string
318
+ Specifies that the content written to the file doesn't end with a newline character. The string
316
319
representations of the input objects are concatenated to form the output. No spaces or newlines are
317
320
inserted between the output strings. No newline is added after the last output string.
318
321
@@ -330,11 +333,11 @@ Accept wildcard characters: False
330
333
331
334
# ## -Width
332
335
333
- Specifies the number of characters in each line of output. Any additional characters are truncated,
334
- not wrapped. If this parameter is not used, the width is determined by the characteristics of the
335
- host. The default for the PowerShell console is 80 characters. If you want to control the width for
336
- all invocations of `Out-File` as well as the redirection operators (`>` and `>>`), set
337
- ` $PSDefaultParameterValues['out-file:width'] = 2000` before using `Out-File`.
336
+ Specifies the maximum number of characters in each line of output. Any additional characters are
337
+ truncated, not wrapped. If this parameter isn't used, the width is determined by the
338
+ characteristics of the host. The default for the PowerShell console is 80 characters. If you want
339
+ to control the width for all invocations of `Out-File` as well as the redirection operators (`>`
340
+ and `>>`), set `$PSDefaultParameterValues['out-file:width'] = 2000` before using `Out-File`.
338
341
339
342
` ` ` yaml
340
343
Type: System.Int32
@@ -366,7 +369,7 @@ Accept wildcard characters: False
366
369
367
370
# ## -WhatIf
368
371
369
- Shows what would happen if the cmdlet runs. The cmdlet is not run.
372
+ Shows what would happen if the cmdlet runs. The cmdlet isn't run.
370
373
371
374
` ` ` yaml
372
375
Type: System.Management.Automation.SwitchParameter
@@ -409,10 +412,10 @@ To send a PowerShell command's output to the `Out-File` cmdlet, use the pipeline
409
412
can store data in a variable and use the **InputObject** parameter to pass data to the `Out-File`
410
413
cmdlet.
411
414
412
- ` Out-File` saves data to a file but it does not produce any output objects to the pipeline.
415
+ ` Out-File` saves data to a file but it doesn't produce any output objects to the pipeline.
413
416
414
417
PowerShell 7.2 added the ability to control how ANSI escape sequences are rendered. ANSI-decorated
415
- output that is passed to `Out-File` can be altered based on the setting of the
418
+ output that's passed to `Out-File` can be changed based on the setting of the
416
419
` $PSStyle.OutputRendering` property. For more information, see
417
420
[about_ANSI_Terminals](/powershell/module/microsoft.powershell.core/about/about_ansi_terminals).
418
421
0 commit comments