How to Find a Folder by Name in PowerShell

To find a folder by name in PowerShell, run Get-ChildItem with -Directory, -Recurse and the folder name in -Filter. The match ignores case:

Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Filter 'Invoices' |
    Select-Object -ExpandProperty FullName

Output:

C:\psfaqs\Projects\2026-08\Invoices
C:\psfaqs\Projects\Clients\Contoso\invoices
C:\psfaqs\Projects\Clients\Fabrikam\Reports\Invoices

I searched a sample Projects folder so the output stays the same. Every example ran in PowerShell 7.6 and Windows PowerShell 5.1 with the same results.

Find folders by partial name

Put wildcards around the part you know. * matches any number of characters and ? matches exactly one:

Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Filter '*invoice*' |
    ForEach-Object { $_.FullName.Replace('C:\psfaqs\Projects\', '') }

Output:

2026-08\Invoices
2026-09\Invoices-Archive
Clients\Contoso\invoices
Clients\Fabrikam\Reports\Invoices
node_modules\invoice-lib
PowerShell find folders by partial name with a wildcard filter
Five folders with invoice anywhere in the name (PowerShell 7)

-Filter is much faster than piping everything to Where-Object, because the file system does the matching. Microsoft lists the wildcard characters in about_Wildcards.

Match a pattern with a regular expression

Wildcards can’t express rules like “four digits, a dash, two digits”. Filter the names with -match for that:

Get-ChildItem -Path C:\psfaqs\Projects -Directory |
    Where-Object Name -Match '^\d{4}-\d{2}$' |
    Select-Object -ExpandProperty Name

Output:

2026-08
2026-09

Keep a -Filter in front when you can, then use -match on the smaller result.

Limit how deep the search goes

A recursive search of a large share can take minutes. -Depth stops it after a set number of levels below the starting folder:

"Depth 1: $((Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Depth 1 -Filter '*invoice*').Name -join ', ')"
"Any depth: $((Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Filter '*invoice*').Count) folders"

Output:

Depth 1: Invoices, Invoices-Archive, invoice-lib
Any depth: 5 folders
PowerShell find folders with -Recurse and -Depth
-Depth 1 finds three of the five matches (PowerShell 7)

-Depth 1 includes the starting folder’s subfolders and their subfolders. The Get-ChildItem documentation describes -Depth and -Filter in detail.

-Exclude doesn’t skip a folder’s contents

It’s natural to use -Exclude to skip a folder like node_modules. But -Exclude only hides the matching folder itself, and the search still walks into it:

$all = Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse -Exclude 'node_modules'
"With -Exclude:  $(($all | Where-Object FullName -like '*node_modules*').Count) folders still inside node_modules"

$clean = Get-ChildItem -Path C:\psfaqs\Projects -Directory -Recurse |
    Where-Object FullName -notlike '*\node_modules*'
"With a path filter: $(($clean | Where-Object FullName -like '*node_modules*').Count) folders inside node_modules"

Output:

With -Exclude:  2 folders still inside node_modules
With a path filter: 0 folders inside node_modules
PowerShell Get-ChildItem -Exclude still returns subfolders of the excluded folder
-Exclude left two node_modules subfolders in the results (Windows PowerShell 5.1)

Filter on the full path instead, as in the second command. It still reads the folder, but none of its contents reach your results.

Include hidden folders

Folders like .git are hidden, and Get-ChildItem skips them unless you add -Force:

"Without -Force: $((Get-ChildItem -Path C:\psfaqs\Projects -Directory -Filter '.git').Count)"
"With -Force:    $((Get-ChildItem -Path C:\psfaqs\Projects -Directory -Filter '.git' -Force).Count)"

Output:

Without -Force: 0
With -Force:    1

Check a folder you already know

When you know the exact path, you don’t need a search. Test-Path with -PathType Container confirms it’s a folder, and quotes handle the space in the name:

Test-Path -Path 'C:\psfaqs\Projects\Backup 2026' -PathType Container
Get-Item -Path 'C:\psfaqs\Projects\Backup 2026' | Select-Object -ExpandProperty Name

Output:

True
Backup 2026

Test-Path in PowerShell covers checking files and folders in more detail.

Skip folders you can’t read

On a file server, some folders deny access and each one prints an error. Silence them, but collect them in a variable so you know what was skipped:

$found = Get-ChildItem -Path C:\psfaqs\Projects, C:\psfaqs\NoSuchFolder -Directory -Filter 'Reports' -Recurse `
    -ErrorAction SilentlyContinue -ErrorVariable problems

"Found: $($found.Count) folder(s)"
"Skipped paths: $($problems.Count)"

Output:

Found: 1 folder(s)
Skipped paths: 1

Here the missing path counts as skipped. On a real share, $problems holds each “Access to the path is denied” error, which you can export.

A reusable Find-Folder function

This wraps the search with a default depth and returns the details you usually want:

function Find-Folder {
    param(
        [Parameter(Mandatory)] [string]$Name,
        [string]$Path = '.',
        [int]$Depth = 10
    )
    Get-ChildItem -Path $Path -Directory -Recurse -Depth $Depth -Filter $Name -ErrorAction SilentlyContinue |
        Select-Object -Property Name, Parent, LastWriteTime, FullName
}

Find-Folder -Name 'Reports' -Path C:\psfaqs\Projects | ForEach-Object { "$($_.Name) in $($_.Parent.Name), full path $($_.FullName)" }

Output:

Reports in Fabrikam, full path C:\psfaqs\Projects\Clients\Fabrikam\Reports

Use Parent.Name or FullName in output. In PowerShell 7, the Parent property prints as a full path, while 5.1 prints only the folder name.

Frequently Asked Questions

How do I find a folder by name in PowerShell?

Run Get-ChildItem -Path C:\ -Directory -Recurse -Filter 'Invoices'. Add -ErrorAction SilentlyContinue to skip folders you can’t read.

How do I find folders by partial name?

Use wildcards: -Filter '*invoice*'. The match ignores case.

How do I search only a few levels deep?

Add -Depth, like Get-ChildItem -Directory -Recurse -Depth 2 -Filter 'Reports'.

Why does -Exclude still return folders inside the excluded folder?

-Exclude only hides items whose own name matches. Filter on the full path, like Where-Object FullName -notlike '*\node_modules*'.

Why doesn’t PowerShell find my .git folder?

It’s hidden. Add -Force to Get-ChildItem to include hidden folders.

Once you have found the folder, these guides help with the next step:

Leave a Comment