Skip to content

Negative values provided to the Get-Content -Tail parameter no longer return the entire content, and instead print an error #21347

@AlexFolland

Description

@AlexFolland

Prerequisites

Steps to reproduce

Negative values for Get-Content parameter -Tail are no longer considered valid, despite the documentation specifying that the accepted type is Int32 which supports negative values, and that providing a negative value results in an unlimited number of lines, effectively showing the full content of the file regardless of its length, even if that length is above $([int]::MaxValue).

The latest documentation for this command says this in the -Tail section:

Negative values cause the cmdlet to return the entire contents.

So, it looks like the current behavior does not match the documented behavior.

I see no current equivalent way to guarantee getting a truly unlimited number of lines beyond $([int]::MaxValue). That returns a very large number, but does not guarantee all lines if the file has more lines than $([int]::MaxValue).

Expected behavior

PS> Get-Content ${filePath} -Wait -Tail -1
<full content of the file at ${filePath} shown here>

Observed behavior

PS> Get-Content ${filePath} -Wait -Tail -1
Get-Content: Cannot validate argument on parameter 'Tail'. The -1 argument is less than the minimum allowed range of 0. Supply an argument that is greater than or equal to 0 and then try the command again.

Error details

I am submitting this issue report on a different computer from the one in which I discovered this issue, so I don't have direct copy access to the output of Get-Error. The error says Get-Content: Cannot validate argument on parameter 'Tail'. The -1 argument is less than the minimum allowed range of 0. Supply an argument that is greater than or equal to 0 and then try the command again. though.

Environment data

I am submitting this issue report on a different computer from the one in which I discovered this issue, so I don't have direct copy access to the output of ${PSVersionTable}. It says the version is 7.4.1 though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions