Skip to content

BUG: Get-Content WRONG ERROR MESSAGE when wildcards yield no files #6954

Closed

Description

@Jaykul

Steps to reproduce

Get-Content C:\NonExistentWildcard*.txt
Get-Content C:\NonExistentWildcard*.txt -Raw
Get-Content  -Delimiter ([char]0) C:\NonExistentWildcard*.txt

Expected behavior

I should get the same error each time:

Get-Content : An object at the specified path C:\NonExistentWildcard*.txt does not exist, or has been filtered by the -Include or -Exclude parameter.

Actual behavior

Three different errors:

Get-Content : An object at the specified path C:\NonExistentWildcard*.txt does not exist, or has been filtered by the -Include or -Exclude parameter.

Get-Content : A parameter cannot be found that matches parameter name 'Raw'.

Get-Content : A parameter cannot be found that matches parameter name 'Delimiter'.

Environment data

> $PSVersionTable
Name                           Value                       
----                           -----                       
PSVersion                      6.0.2                       
PSEdition                      Core                        
GitCommitId                    v6.0.2                      
OS                             Microsoft Windows 10.0.17134
Platform                       Win32NT                     
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}     
PSRemotingProtocolVersion      2.3                         
SerializationVersion           1.1.0.1                     
WSManStackVersion              3.0                         

NOTE: This bug exists back to 5.1 at least

Activity

  1. Jaykul commented on May 29, 2018

    @Jaykul
    ContributorAuthor

    Just don't ask me how long I spent running builds with variations of this command before I finally figured out the problem.

  2. MaximoTrinidad commented on May 29, 2018

    @MaximoTrinidad

    It can be repo in Preview-6:

    PS C:\Program Files\PowerShell\6-preview> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      6.1.0-preview.2
    PSEdition                      Core
    GitCommitId                    v6.1.0-preview.2
    OS                             Microsoft Windows 10.0.17677
    Platform                       Win32NT
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    WSManStackVersion              3.0
    

    get-contect_issue_2018-05-29_12-38-59

  3. added
    Issue-Bug
    on Jun 1, 2018
  4. suprak commented on Oct 5, 2018

    @suprak

    This is also the case if the path has square brackets.

    For example,

    Get-Content -Path 'C:\Tempt\[Foo] Bar\log.txt' -Raw
    

    The workaround is to use LiteralPath.

    Get-Content -LiteralPath 'C:\Tempt\[Foo] Bar\log.txt' -Raw
    
  5. mrp100461 commented on Apr 15, 2020

    @mrp100461

    $vbppath = 'C:\W10Build-Nexus\Nexus\NexUSVB6\NEXUS\Load Configuration File\CIUSConfigFileIO.vbp'
    $Content = (Get-Content -LiteralPath $vbppath -Raw)
    A parameter cannot be found that matches parameter name 'Raw'.
    PSVersion 5.1.16299.251 what fix is there for this

  6. suprak commented on Apr 15, 2020

    @suprak

    Mark Pearson (@mrp100461)

    I can't repro missing -Raw switch,

    PS C:\Users\Administrator> $PSVersionTable
    
    Name                           Value
    ----                           -----
    PSVersion                      5.1.14393.3471
    PSEdition                      Desktop
    PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
    BuildVersion                   10.0.14393.3471
    CLRVersion                     4.0.30319.42000
    WSManStackVersion              3.0
    PSRemotingProtocolVersion      2.3
    SerializationVersion           1.1.0.1
    
    PS C:\Users\Administrator> Get-Content -LiteralPath 'C:\Users\Administrator\t.txt' -Raw
    Foo
    
  7. mrp100461 commented on Apr 17, 2020

    @mrp100461

    @surpack It need spaces in the path

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Issue-BugResolution-FixedWG-Cmdlets

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions