How to Find a Folder by Name in PowerShell?

If you’re a Windows administrator, DevOps engineer, or IT professional, you’ve probably needed to locate a folder buried deep within a directory structure. Manually doing this is really tough. So, you can use PowerShell for this.

In this tutorial, you’ll learn how to find a folder by name using PowerShell, step‑by‑step with real examples.

The Core Cmdlet: Get-ChildItem

The main PowerShell command for finding files and folders is Get-ChildItem, often abbreviated as gci. It lists items (files and directories) in a specified path.

Basic Syntax

Here is the basic syntax:

Get-ChildItem -Path "C:\Path\To\Search" -Directory -Recurse -ErrorAction SilentlyContinue
  • -Path — The directory you want to search.
  • -Directory — Ensures only folders (not files) are returned.
  • -Recurse — Searches all subdirectories.
  • -ErrorAction SilentlyContinue — Suppresses access‑denied errors.

Check out Create a Folder with Today’s Date and Copy Files to it using PowerShell

Example 1: Find a Folder by Exact Name

If you know the exact folder name, you can use the -Filter parameter for a fast, efficient search:

Get-ChildItem -Path "C:\Users" -Directory -Filter "Documents" -Recurse

This command searches under C:\Users for any folder named Documents, recursively checking all subfolders.

Here is the exact output in the screenshot below:

Find a Folder by Name in PowerShell

Tip: The -Filter parameter is processed by the filesystem provider, making it faster than using Where-Object.

Example 2: Find Folders by Partial Name (Wildcard Search)

Sometimes, you only remember part of the folder name. In that case, use a wildcard character (*):

Get-ChildItem -Path "C:\Projects" -Directory -Recurse -Filter "*Archive*"

This finds all folders with “Archive” anywhere in their name — e.g., OldArchive, Archive2025, or ProjectArchive.

Alternatively, you can use Where-Object for more advanced pattern matching:

Get-ChildItem -Path "C:\Projects" -Directory -Recurse |
Where-Object { $_.Name -like "*Archive*" }

Check out Set Folder Permissions Using PowerShell

Example 3: Case‑Insensitive Folder Search

PowerShell searches are case‑insensitive by default on Windows, but if you want to enforce case sensitivity (useful in cross‑platform environments), you can do this:

Get-ChildItem -Path "/mnt/data" -Directory -Recurse |
Where-Object { $_.Name -clike "*Archive*" }

Here, -clike performs a case‑sensitive comparison.

Example 4: Find Folders by Name and Modified Date

To narrow down results, you can combine name and date filters like the below PowerShell script.

Get-ChildItem -Path "C:\Logs" -Directory -Recurse |
Where-Object { $_.Name -like "*Backup*" -and $_.LastWriteTime -gt (Get-Date).AddDays(-7) }

This finds all folders with “Backup” in the name that were modified within the last 7 days.

Example 5: Export Folder Search Results to a CSV File

For documentation or auditing purposes, you might want to export your search results:

Get-ChildItem -Path "D:\Data" -Directory -Recurse -Filter "*Reports*" |
Select-Object FullName, LastWriteTime |
Export-Csv -Path "C:\Temp\ReportFolders.csv" -NoTypeInformation

This creates a CSV file listing all folders containing “Reports” along with their last modified date.

Check out Create Folder Structure from CSV using PowerShell

Example 6: Find Folders on a Remote Computer

With PowerShell remoting, you can perform folder searches on remote systems:

Invoke-Command -ComputerName "Server01" -ScriptBlock {
    Get-ChildItem -Path "C:\Logs" -Directory -Recurse -Filter "*Archive*"
}

Make sure PowerShell Remoting is enabled on the target machine (Enable-PSRemoting -Force).

Example 7: Using Get-Item and Test-Path for Specific Folder Checks

If you just want to check whether a specific folder exists, use Test-Path:

Test-Path "C:\Projects\Archive2024"

Returns True if the folder exists, otherwise False.

Or retrieve the folder’s details directly:

Get-Item "C:\Projects\Archive2024"

Example 8: Create a Reusable PowerShell Function

If you frequently search for folders, wrap your logic into a reusable function:

function Find-FolderByName {
    param(
        [Parameter(Mandatory=$true)][string]$Path,
        [Parameter(Mandatory=$true)][string]$Name
    )

    Get-ChildItem -Path $Path -Directory -Recurse -ErrorAction SilentlyContinue |
    Where-Object { $_.Name -like "*$Name*" }
}

Usage:

This is how you can use it:

Find-FolderByName -Path "C:\Projects" -Name "Archive"

This function can be saved in your PowerShell profile for everyday use.

Read Create Multiple Folders in PowerShell

Example 9: Find Folders and Perform Actions on Them

You can combine folder search with additional actions, such as copying or deleting:

Get-ChildItem -Path "C:\Data" -Directory -Recurse -Filter "*Temp*" |
ForEach-Object {
    Remove-Item $_.FullName -Recurse -Force
}

⚠️ Warning: Always test with -WhatIf before deleting:

Remove-Item $_.FullName -Recurse -Force -WhatIf

In this tutorial, I explained how to find folders by name in PowerShell by providing various examples.

  • Use Get-ChildItem to find folders by name
  • Filter by partial names, dates, and attributes
  • Export results to CSV
  • Search remote systems
  • Optimize performance

You may also like the following tutorials:

Leave a Comment

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

FREE Download an eBook that contains 100 PowerShell cmdlets with complete script and examples.