Skip to content

Commit ec789da

Browse files
(GH-143023) Clarify Width param for Out-File (#10310)
Prior to this change, the **Width** paramter of the `Out-File` cmdlet stated that it specified the number of characters in each line of output rather than the maximum number of characters. This change: - Clarifies the parameter documentation for specifying the maximum width, rather than the total width. - Resolves #10309 - Fixes AB#132023
1 parent 6200d65 commit ec789da

File tree

4 files changed

+117
-105
lines changed

4 files changed

+117
-105
lines changed

reference/5.1/Microsoft.PowerShell.Utility/Out-File.md

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 12/12/2022
5+
ms.date: 07/27/2023
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-file?view=powershell-5.1&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Out-File
@@ -18,15 +18,15 @@ Sends output to a file.
1818
### ByPath (Default)
1919

2020
```
21-
Out-File [-FilePath] <string> [[-Encoding] <string>] [-Append] [-Force] [-NoClobber] [-Width <int>]
22-
[-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>]
21+
Out-File [-FilePath] <string> [[-Encoding] <string>] [-Append] [-Force] [-NoClobber]
22+
[-Width <int>] [-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>]
2323
```
2424

2525
### ByLiteralPath
2626

2727
```
28-
Out-File [[-Encoding] <string>] -LiteralPath <string> [-Append] [-Force] [-NoClobber] [-Width <int>]
29-
[-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>]
28+
Out-File [[-Encoding] <string>] -LiteralPath <string> [-Append] [-Force] [-NoClobber]
29+
[-Width <int>] [-NoNewline] [-InputObject <psobject>] [-WhatIf] [-Confirm] [<CommonParameters>]
3030
```
3131

3232
## DESCRIPTION
@@ -95,15 +95,15 @@ Out-File -FilePath .\Process.txt -InputObject $Procs -Encoding ASCII -Width 50
9595
```
9696

9797
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.
103103

104104
### Example 4: Use a provider and send output to a file
105105

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
107107
drive. Use the `Get-PSProvider` cmdlet to view the providers on your local computer. For more
108108
information, see [about_Providers](../Microsoft.Powershell.Core/About/about_Providers.md).
109109

@@ -132,8 +132,8 @@ The `Set-Location` command uses the **Path** parameter to set the current locati
132132
provider `Alias:`. The `Get-Location` cmdlet displays the complete path for `Alias:`.
133133
`Get-ChildItem` sends objects down the pipeline to the `Out-File` cmdlet. `Out-File` uses the
134134
**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.
137137

138138
### Example 5: Set file output width for entire scope
139139

@@ -151,7 +151,9 @@ function DemoDefaultOutFileWidth() {
151151
152152
Get-ChildItem Env:\ > $logFile
153153
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
155157
156158
Get-Process | Format-Table Id,SI,Name,Path,MainWindowTitle >> $logFile
157159
}
@@ -234,8 +236,8 @@ Accept wildcard characters: False
234236

235237
### -Force
236238

237-
Overrides the read-only attribute and overwrites an existing read-only file. The **Force** parameter
238-
does not override security restrictions.
239+
Overrides the read-only attribute and overwrites an existing read-only file. The **Force**
240+
parameter doesn't override security restrictions.
239241

240242
```yaml
241243
Type: System.Management.Automation.SwitchParameter
@@ -268,10 +270,11 @@ Accept wildcard characters: False
268270

269271
### -LiteralPath
270272

271-
Specifies the path to the output file. The **LiteralPath** parameter is used exactly as it is typed.
272-
Wildcard characters are not accepted. If the path includes escape characters, enclose it in single
273+
Specifies the path to the output file. The **LiteralPath** parameter is used exactly as it's typed.
274+
Wildcard characters aren't accepted. If the path includes escape characters, enclose it in single
273275
quotation marks. Single quotation marks tell PowerShell not to interpret any characters as escape
274-
sequences. For more information, see [about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
276+
sequences. For more information, see
277+
[about_Quoting_Rules](../Microsoft.Powershell.Core/About/about_Quoting_Rules.md).
275278

276279
```yaml
277280
Type: System.String
@@ -305,7 +308,7 @@ Accept wildcard characters: False
305308

306309
### -NoNewline
307310

308-
Specifies that the content written to the file does not end with a newline character. The string
311+
Specifies that the content written to the file doesn't end with a newline character. The string
309312
representations of the input objects are concatenated to form the output. No spaces or newlines are
310313
inserted between the output strings. No newline is added after the last output string.
311314

@@ -323,11 +326,11 @@ Accept wildcard characters: False
323326

324327
### -Width
325328

326-
Specifies the number of characters in each line of output. Any additional characters are truncated,
327-
not wrapped. If this parameter is not used, the width is determined by the characteristics of the
328-
host. The default for the PowerShell console is 80 characters. If you want to control the width for
329-
all invocations of `Out-File` as well as the redirection operators (`>` and `>>`), set
330-
`$PSDefaultParameterValues['out-file:width'] = 2000` before using `Out-File`.
329+
Specifies the maximum number of characters in each line of output. Any additional characters are
330+
truncated, not wrapped. If this parameter isn't used, the width is determined by the
331+
characteristics of the host. The default for the PowerShell console is 80 characters. If you want
332+
to control the width for all invocations of `Out-File` as well as the redirection operators (`>`
333+
and `>>`), set `$PSDefaultParameterValues['out-file:width'] = 2000` before using `Out-File`.
331334

332335
```yaml
333336
Type: System.Int32
@@ -359,7 +362,7 @@ Accept wildcard characters: False
359362

360363
### -WhatIf
361364

362-
Shows what would happen if the cmdlet runs. The cmdlet is not run.
365+
Shows what would happen if the cmdlet runs. The cmdlet isn't run.
363366

364367
```yaml
365368
Type: System.Management.Automation.SwitchParameter
@@ -402,7 +405,7 @@ To send a PowerShell command's output to the `Out-File` cmdlet, use the pipeline
402405
can store data in a variable and use the **InputObject** parameter to pass data to the `Out-File`
403406
cmdlet.
404407

405-
`Out-File` saves data to a file but it does not produce any output objects to the pipeline.
408+
`Out-File` saves data to a file but it doesn't produce any output objects to the pipeline.
406409

407410
## RELATED LINKS
408411

reference/7.2/Microsoft.PowerShell.Utility/Out-File.md

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
external help file: Microsoft.PowerShell.Commands.Utility.dll-Help.xml
33
Locale: en-US
44
Module Name: Microsoft.PowerShell.Utility
5-
ms.date: 12/12/2022
5+
ms.date: 07/27/2023
66
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.utility/out-file?view=powershell-7.2&WT.mc_id=ps-gethelp
77
schema: 2.0.0
88
title: Out-File
@@ -95,15 +95,15 @@ Out-File -FilePath .\Process.txt -InputObject $Procs -Encoding ASCII -Width 50
9595
```
9696

9797
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.
103103

104104
### Example 4: Use a provider and send output to a file
105105

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
107107
drive. Use the `Get-PSProvider` cmdlet to view the providers on your local computer. For more
108108
information, see [about_Providers](../Microsoft.Powershell.Core/About/about_Providers.md).
109109

@@ -132,8 +132,8 @@ The `Set-Location` command uses the **Path** parameter to set the current locati
132132
provider `Alias:`. The `Get-Location` cmdlet displays the complete path for `Alias:`.
133133
`Get-ChildItem` sends objects down the pipeline to the `Out-File` cmdlet. `Out-File` uses the
134134
**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.
137137

138138
### Example 5: Set file output width for entire scope
139139

@@ -151,7 +151,9 @@ function DemoDefaultOutFileWidth() {
151151
152152
Get-ChildItem Env:\ > $logFile
153153
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
155157
156158
Get-Process | Format-Table Id,SI,Name,Path,MainWindowTitle >> $logFile
157159
}
@@ -201,8 +203,8 @@ The acceptable values for this parameter are as follows:
201203
- `utf8NoBOM`: Encodes in UTF-8 format without Byte Order Mark (BOM)
202204
- `utf32`: Encodes in UTF-32 format.
203205

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
206208
`-Encoding "windows-1251"`). For more information, see the .NET documentation for
207209
[Encoding.CodePage](/dotnet/api/system.text.encoding.codepage?view=netcore-2.2).
208210

@@ -241,8 +243,8 @@ Accept wildcard characters: False
241243

242244
### -Force
243245

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.
246248

247249
```yaml
248250
Type: System.Management.Automation.SwitchParameter
@@ -275,10 +277,11 @@ Accept wildcard characters: False
275277

276278
### -LiteralPath
277279

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
280282
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).
282285

283286
```yaml
284287
Type: System.String
@@ -312,7 +315,7 @@ Accept wildcard characters: False
312315

313316
### -NoNewline
314317

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
316319
representations of the input objects are concatenated to form the output. No spaces or newlines are
317320
inserted between the output strings. No newline is added after the last output string.
318321

@@ -330,11 +333,11 @@ Accept wildcard characters: False
330333

331334
### -Width
332335

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`.
338341

339342
```yaml
340343
Type: System.Int32
@@ -366,7 +369,7 @@ Accept wildcard characters: False
366369

367370
### -WhatIf
368371

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.
370373

371374
```yaml
372375
Type: System.Management.Automation.SwitchParameter
@@ -409,10 +412,10 @@ To send a PowerShell command's output to the `Out-File` cmdlet, use the pipeline
409412
can store data in a variable and use the **InputObject** parameter to pass data to the `Out-File`
410413
cmdlet.
411414

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.
413416

414417
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
416419
`$PSStyle.OutputRendering` property. For more information, see
417420
[about_ANSI_Terminals](/powershell/module/microsoft.powershell.core/about/about_ansi_terminals).
418421

0 commit comments

Comments
 (0)