Skip to content

Commit

Permalink
Negative ReadCount read all content (MicrosoftDocs#10526)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdwheeler authored Oct 13, 2023
1 parent a9d1800 commit 4a046db
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
4 changes: 2 additions & 2 deletions reference/5.1/Microsoft.PowerShell.Management/Get-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Management
ms.date: 06/21/2023
ms.date: 10/13/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content?view=powershell-5.1&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Get-Content
Expand Down Expand Up @@ -515,7 +515,7 @@ Accept wildcard characters: False
### -ReadCount

Specifies how many lines of content are sent through the pipeline at a time. The default value is 1.
A value of 0 (zero) sends all the content at one time.
A value of 0 (zero) or negative numbers sends all the content at one time.

This parameter doesn't change the content displayed, but it does affect the time it takes to
display the content. As the value of **ReadCount** increases, the time it takes to return the first
Expand Down
16 changes: 8 additions & 8 deletions reference/7.2/Microsoft.PowerShell.Management/Get-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Management
ms.date: 06/21/2023
ms.date: 10/13/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.2&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Get-Content
Expand Down Expand Up @@ -286,6 +286,12 @@ introduced in Windows PowerShell 6.0.
A warning occurs when you use the **AsByteStream** parameter with the **Encoding** parameter. The
**AsByteStream** parameter ignores any encoding and the output is returned as a stream of bytes.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object. Piping single-byte output to `Set-Content` causes errors unless
you use the **AsByteStream** parameter with `Set-Content`.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Expand Down Expand Up @@ -371,12 +377,6 @@ The acceptable values for this parameter are as follows:
Encoding is a dynamic parameter that the **FileSystem** provider adds to the `Get-Content` cmdlet.
This parameter is available only in file system drives.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object, which causes errors when you use the `Set-Content` cmdlet to write
the bytes to a file unless you use **AsByteStream** parameter.

Beginning with PowerShell 6.2, the **Encoding** parameter also allows numeric IDs of registered code
pages (like `-Encoding 1251`) or string names of registered code pages (like
`-Encoding "windows-1251"`). For more information, see the .NET documentation for
Expand Down Expand Up @@ -548,7 +548,7 @@ Accept wildcard characters: False
### -ReadCount

Specifies how many lines of content are sent through the pipeline at a time. The default value is 1.
A value of 0 (zero) sends all the content at one time.
A value of 0 (zero) or negative numbers sends all the content at one time.

This parameter doesn't change the content displayed, but it does affect the time it takes to
display the content. As the value of **ReadCount** increases, the time it takes to return the first
Expand Down
16 changes: 8 additions & 8 deletions reference/7.3/Microsoft.PowerShell.Management/Get-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Management
ms.date: 06/21/2023
ms.date: 10/13/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.3&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Get-Content
Expand Down Expand Up @@ -286,6 +286,12 @@ introduced in Windows PowerShell 6.0.
A warning occurs when you use the **AsByteStream** parameter with the **Encoding** parameter. The
**AsByteStream** parameter ignores any encoding and the output is returned as a stream of bytes.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object. Piping single-byte output to `Set-Content` causes errors unless
you use the **AsByteStream** parameter with `Set-Content`.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Expand Down Expand Up @@ -371,12 +377,6 @@ The acceptable values for this parameter are as follows:
Encoding is a dynamic parameter that the **FileSystem** provider adds to the `Get-Content` cmdlet.
This parameter is available only in file system drives.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object, which causes errors when you use the `Set-Content` cmdlet to write
the bytes to a file unless you use **AsByteStream** parameter.

Beginning with PowerShell 6.2, the **Encoding** parameter also allows numeric IDs of registered code
pages (like `-Encoding 1251`) or string names of registered code pages (like
`-Encoding "windows-1251"`). For more information, see the .NET documentation for
Expand Down Expand Up @@ -548,7 +548,7 @@ Accept wildcard characters: False
### -ReadCount

Specifies how many lines of content are sent through the pipeline at a time. The default value is 1.
A value of 0 (zero) sends all the content at one time.
A value of 0 (zero) or negative numbers sends all the content at one time.

This parameter doesn't change the content displayed, but it does affect the time it takes to
display the content. As the value of **ReadCount** increases, the time it takes to return the first
Expand Down
23 changes: 12 additions & 11 deletions reference/7.4/Microsoft.PowerShell.Management/Get-Content.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
external help file: Microsoft.PowerShell.Commands.Management.dll-Help.xml
Locale: en-US
Module Name: Microsoft.PowerShell.Management
ms.date: 06/21/2023
ms.date: 10/13/2023
online version: https://learn.microsoft.com/powershell/module/microsoft.powershell.management/get-content?view=powershell-7.4&WT.mc_id=ps-gethelp
schema: 2.0.0
title: Get-Content
Expand Down Expand Up @@ -286,6 +286,12 @@ introduced in Windows PowerShell 6.0.
A warning occurs when you use the **AsByteStream** parameter with the **Encoding** parameter. The
**AsByteStream** parameter ignores any encoding and the output is returned as a stream of bytes.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object. Piping single-byte output to `Set-Content` causes errors unless
you use the **AsByteStream** parameter with `Set-Content`.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Expand Down Expand Up @@ -371,12 +377,6 @@ The acceptable values for this parameter are as follows:
Encoding is a dynamic parameter that the **FileSystem** provider adds to the `Get-Content` cmdlet.
This parameter is available only in file system drives.

When reading from and writing to binary files, use the **AsByteStream** parameter and a value of 0
for the **ReadCount** parameter. A **ReadCount** value of 0 reads the entire file in a single read
operation. The default **ReadCount** value, 1, reads one byte in each read operation and converts
each byte into a separate object, which causes errors when you use the `Set-Content` cmdlet to write
the bytes to a file unless you use **AsByteStream** parameter.

Beginning with PowerShell 6.2, the **Encoding** parameter also allows numeric IDs of registered code
pages (like `-Encoding 1251`) or string names of registered code pages (like
`-Encoding "windows-1251"`). For more information, see the .NET documentation for
Expand Down Expand Up @@ -548,7 +548,7 @@ Accept wildcard characters: False
### -ReadCount

Specifies how many lines of content are sent through the pipeline at a time. The default value is 1.
A value of 0 (zero) sends all the content at one time.
A value of 0 (zero) or negative numbers sends all the content at one time.

This parameter doesn't change the content displayed, but it does affect the time it takes to
display the content. As the value of **ReadCount** increases, the time it takes to return the first
Expand Down Expand Up @@ -596,7 +596,8 @@ Accept wildcard characters: False
### -Tail

Specifies the number of lines from the end of a file or other item. You can use the **Tail**
parameter name or its alias, **Last**. Negative numbers aren't supported.
parameter name or its alias, **Last**. Negative values cause the cmdlet to return the entire
contents.

This parameter was introduced in PowerShell 3.0.

Expand All @@ -614,8 +615,8 @@ Accept wildcard characters: False

### -TotalCount

Specifies the number of lines from the beginning of a file or other item. Negative numbers aren't
supported.
Specifies the number of lines from the beginning of a file or other item. Negative values cause the
cmdlet to return the entire contents.

You can use the **TotalCount** parameter name or its aliases, **First** or **Head**.

Expand Down

0 comments on commit 4a046db

Please sign in to comment.