Search code examples
powershellsearchcase-sensitive

How to do a case-sensitive file search with PowerShell?


Get-ChildItem -Path C:\ -Filter CAPS*

finds caps.txt I want to make sure it will only find CAPS.txt (or e.g. CAPS901918.whatever)

I've tried find ways to pipe the Filter to an expression like:

{ $_.What_I_just_said_to_filter_on -like [A-Z] }

or suppress output after receiving results but I have found nothing.


Solution

  • try piping Get-Childitem to Where-Object like this:

    Get-Childitem -Path C:\ | Where-Object {$_.what_you_want_to_filter -cmatch "REGEX"}
    

    here it is with like syntax (thanks FLGMwt)

    Get-Childitem -Path C:\ | Where-Object {$_.Name -clike "CAPS*"}