Powershell Command for searching & finding 2 files from a diectory


I am looking for the shortest PowerShell command to search and display 2 files in my home directory. However, the command I am using is not technically right. I am looking for a better powershell command.

Here is my problem.

I have two files called “Letter to Mom” & “Letter to Dad” in my Home Directory inside a folder called “myletter”

C:\Users\Apple> is my home directory.

I used the following command Get-ChildItem -Filter Letter* -Recurse

However, this is not right because it will list all files starting with “Letter”.

Can anyone provide a better ‘smallest’ command which only lists the “Letter to Mom” & “Letter to Dad” files


Any input will be appreciated

What about Get-ChildItem -Filter “Letter to*” -Recurse

Any other options?

What’s wrong with it? It’s pretty short. To make sure not to catch the “letter to parents:wink: you have to make it more complex …

Get-ChildItem -Path ‘D:\sample’ -Filter ‘Letter to*’ -Recurse |
Where-Object -Property BaseName -Match -Value ‘mom|dad’

Why recurse? You know where they exist.

gci “$env:HOMEPATH\myletter” “letter to *”

Thanks everyone


There is another problem.

If we add another file called letter to grandfather, it should not be there.

I mean if we write the

gci “$env:HOMEPATH\myletter” “letter to *”

Get-ChildItem -Filter “Letter to*” -Recurse

codes, the whole 3 files will appear.
can you solve?

Olaf already did.

Get-ChildItem -Path 'D:\sample' -Filter 'Letter to*' -Recurse |
Where-Object -Property BaseName -Match -Value 'mom|dad'

Here is another way to only get mom and dad.

gci -include "*dad*","*mom*" "letter to *" -recurse

Powershell.org is not a free code writing service. What’s the actual problem you’re trying to solve? We won’t write Powershell code piece by piece for you.

Get-ChildItem -Filter Letter* -Recurse | where {$_.name -match ‘mom|dad’} | select name
It’s pretty much the same context as posted by Olaf.