How to search for a folder with PowerShell

Get-ChildItem C:\test -recurse | Where-Object {$_.PSIsContainer -eq $true -and $_.Name -match "keyword"}

I believe there's no dedicated cmdlet for searching files.

Edit in response to @Notorious comment: Since Powershell 3.0 this is much easier, since switches -Directory and -File were added to Get-ChildItem. So if you want it short you've got:

ls c:\test *key* -Recurse -Directory

With command alias and tab-completion for switches it's a snap. I just missed that the first time.


Here is my version, which is only slightly different:

gci -Recurse -Filter "your_folder_name" -Directory -ErrorAction SilentlyContinue -Path "C:\"

some more info:

-Filter "your_folder_name"

From documentation: Filters are more efficient than other parameters. The provider applies filter when the cmdlet gets the objects rather than having PowerShell filter the objects after they're retrieved. The filter string is passed to the .NET API to enumerate files. The API only supports * and ? wildcards.

-Directory 

Only examine directories, also could be -File

-ErrorAction SilentlyContinue 

Silences any warnings

-Path "C:\"

Specifies a path to start searching from

https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/get-childitem?view=powershell-7

Tags:

Powershell