PowerShell Find File by Name Wildcard Examples

PowerShell provides powerful file search capabilities using wildcard patterns and cmdlets. In this tutorial, I will explain how to find files by name wildcard in PowerShell with examples. You will learn multiple methods to locate files using pattern matching in PowerShell.

What Are Wildcards?

Before we dive in, let’s understand wildcards:

  • * (asterisk) – Matches any number of characters (including zero)
  • ? (question mark) – Matches exactly one character
  • [ ] (brackets) – Matches any single character within the brackets
  • Hyphen (-): Defines a range within brackets (e.g., [a-z])

Examples:

  • *.txt – All files ending with .txt
  • report?.docx – Matches report1.docx, reportA.docx, but not report10.docx
  • file[123].txt – Matches file1.txt, file2.txt, or file3.txt
  • file[0-9].txt matches file0.txt through file9.txt

Method 1: Using Get-ChildItem

Get-ChildItem (alias: gci, ls, dir) is mostly used in PowerShell to find files. It’s the equivalent of the Windows Command Prompt’s dir command, but with much more power and flexibility. When you need to search for files by name, extension, or pattern in PowerShell, Get-ChildItem is your go-to solution for file discovery and directory navigation.

Basic Syntax

Here is the basic syntax to use it.

Get-ChildItem -Path "C:\YourFolder" -Filter "*.txt"

Here are some examples.

To find all .txt files in the current directory, you can use the below PowerShell cmdlet with a wildcard.

Get-ChildItem -Filter "*.txt"

Similarly, to find files in a specific folder, you can use the following cmdlet.

You can see the exact output in the screenshot below:

PowerShell Find File by Name Wildcard
Get-ChildItem -Path "C:\Documents" -Filter "invoice*.pdf"

Check out PowerShell Get-ChildItem Filter Examples

Method 2: Using Where-Object for Complex Filtering and Advanced File Search

When you need more control beyond simple wildcards, combine Get-ChildItem with Where-Object for advanced filtering. This method allows you to filter files based on multiple criteria, properties, and conditions simultaneously.

Where-Object is essential for complex file searches that require finding files by size, date modified, name pattern, or any combination of file attributes.

Here is an example to find files with names containing specific text using the wildcard and the where-object cmdlet.

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

Here is another example of finding files matching multiple criteria (file type and size):

Get-ChildItem -Path "C:\Reports" -Recurse | 
    Where-Object { $_.Name -like "*.xlsx" -and $_.Length -gt 1MB }

Below is another example of using regular expressions (regex) for advanced patterns:

Get-ChildItem -Path "C:\Data" -Recurse | 
    Where-Object { $_.Name -match "^report_\d{4}\.txt$" }

This finds files like: report_2023.txt, report_2024.txt

Here is another PowerShell script for finding files NOT matching a pattern (inverse search):

Get-ChildItem -Path "C:\Temp" | 
    Where-Object { $_.Name -notlike "temp*" }

Comparison Operators for Where-Object File Filtering

OperatorDescriptionExample
-likeWildcard matching$_.Name -like "*.doc"
-notlikeInverse wildcard$_.Name -notlike "temp*"
-matchRegex matching$_.Name -match "\d{3}"
-eqExact match$_.Name -eq "file.txt"

Read PowerShell Get-ChildItem Files Only

Method 3: Using the -LiteralPath Parameter for Special Characters

When your file names contain special characters that could be interpreted as wildcards, use the -LiteralPath parameter to perform exact path matching.

This method is useful when working with files that have brackets, asterisks, or other wildcard characters in their actual filenames.

LiteralPath tells PowerShell to treat the path exactly as written without interpreting any characters as wildcard patterns, ensuring accurate file location and preventing unexpected search results.

Get-ChildItem -LiteralPath "C:\Files\Report[Final].txt"

Without -LiteralPath, the brackets would be interpreted as a wildcard pattern!

Check out Find the Most Recent File in a Directory with PowerShell

PowerShell Find File by Name Wildcard Examples

Now, let me show you some examples of PowerShell finding files by name with a wildcard.

Example 1: Find Files with Specific Extension Using Asterisk Wildcard

Here is an examle of how to find files with specific extension using asterisk wildcard.

Get-ChildItem -Path "C:\Users\Documents" -Filter "*.txt"

What this does:

  • Searches for all text files (files with .txt extension) in the Documents folder
  • The asterisk (*) wildcard matches any filename regardless of length
  • Perfect for locating configuration files, log files, or document types

Use cases:

  • Finding all Excel files: *.xlsx
  • Locating PDF documents: *.pdf
  • Searching image files: *.jpg

Example 2: Recursive File Search Through Subdirectories (Deep Search)

Here is an example of a recursive file search through subdirectories using a wildcard in PowerShell.

Get-ChildItem -Path "C:\Projects" -Filter "*.log" -Recurse

Key features:

  • -Recurse parameter enables deep directory scanning
  • Searches through all subfolders and nested directories
  • Finds files at any depth level in the directory tree

Why use recursive search:

  • Don’t know the exact folder location
  • Need to scan the entire project structures
  • Searching network drives or large directory trees
  • Locating files scattered across multiple subdirectories

Check out Find Passwords in Files with PowerShell

Example 3: Find Files Starting with Specific Text (Prefix Matching)

Here is an example of using the wildcard to find files starting with specific text using PowerShell.

Get-ChildItem -Path "C:\Reports" -Filter "Report_*.xlsx"

Pattern breakdown:

  • Report_ = Fixed prefix (must match exactly)
  • * = Any characters following the prefix
  • .xlsx = Specific file extension

Here are some examples.

# Find backup files starting with "backup"
Get-ChildItem -Filter "backup*.zip"

# Find all invoice files
Get-ChildItem -Filter "Invoice_*.pdf"

# Find log files by date prefix
Get-ChildItem -Filter "2025*.log"

This approach helps organize and retrieve files that follow organizational naming standards or date-based conventions.

Example 4: Find Files Ending with Specific Pattern (Suffix Matching)

Here is another example of finding files ending with a specific pattern in PowerShell using a wildcard.

Get-ChildItem -Path "C:\Backups" -Filter "*_backup.zip"

What gets matched:

  • database_backup.zip
  • 2025_backup.zip
  • important_data_backup.zip
  • backup_file.zip (doesn’t end with the pattern)

Practical applications:

  • Backup files: *_backup.*
  • Processed documents: *_processed.docx
  • Finalized reports: *_final.pdf
  • Archived data: *_archive.zip

Example 5: Single Character Wildcard Using Question Mark

Here is an example of using the wildcard question mark in PowerShell to get the files.

Get-ChildItem -Path "C:\Data" -Filter "file?.txt"

Understanding the ? wildcard:

PatternMatchesDoesn’t Match
file?.txtfile1.txt, file2.txt, fileA.txtfile10.txt, file.txt, fileAB.txt
data?.csvdata1.csv, dataX.csvdata10.csv, data.csv
log??.txtlog01.txt, logAB.txtlog1.txt, log123.txt

When to use:

  • Numbered sequences with fixed digits
  • Single-letter version indicators
  • Strict character-position matching requirements

Read Find a Folder by Name in PowerShell

Example 6: Multiple Question Marks for Fixed-Length Patterns

We can also use multiple question mark wildcards for finding files in PowerShell.

Get-ChildItem -Path "C:\Invoices" -Filter "INV-????.pdf"

Pattern specifications:

  • INV- = Required prefix
  • ???? = Exactly 4 characters (no more, no less)
  • .pdf = Required extension

Examples of matched files:

✅ INV-0001.pdf
✅ INV-2025.pdf
✅ INV-ABCD.pdf
❌ INV-001.pdf (only 3 characters)
❌ INV-12345.pdf (5 characters)

Perfect for:

  • ID numbers with fixed lengths
  • Date codes (MMDD, YYYY)
  • Reference numbers with standard formats
  • Employee/customer codes

Example 7: Combining Multiple Wildcards in One Pattern

We can also combine multiple wildcards in one pattern in PowerShell.

Get-ChildItem -Path "C:\Logs" -Filter "app_*.log" -Recurse | Where-Object {$_.Name -like "*error*"}

Two-stage filtering approach:

Stage 1 (Filesystem level):

  • Finds all files matching app_*.log
  • Fast and efficient
  • Uses native Windows search

Stage 2 (PowerShell level):

  • Filters results containing “error” in filename
  • More flexible pattern matching
  • Additional condition checking

Alternative complex patterns:

# Find config files with version numbers
Get-ChildItem -Filter "config_*.xml" | Where-Object {$_.Name -match "\d+"}

# Find images excluding thumbnails
Get-ChildItem -Filter "*.jpg" | Where-Object {$_.Name -notlike "*thumb*"}

Check out How to Test If a File Exists in PowerShell?

Example 8: Character Range Matching with Square Brackets

We can also do character range matches using square brackets in PowerShell.

Get-ChildItem -Path "C:\Archives" -Filter "file[0-9].txt"

Character range options:

PatternMatchesUse Case
[0-9]Any single digit (0-9)Numbered files
[a-z]Any lowercase letterLettered versions
[A-Z]Any uppercase letterCapitalized codes
[aeiou]Specific characters onlyCustom character sets
[0-9][0-9]Two-digit numbers (00-99)Day/month codes

Practical examples:

# Find files with single digit
Get-ChildItem -Filter "log[0-9].txt"

# Find files with single letter
Get-ChildItem -Filter "version[A-Z].docx"

# Find files with two digits
Get-ChildItem -Filter "day[0-9][0-9].csv"

In this tutorial, I explained how to find files by name wildcard in PowerShell with a few real examples. Do let me know if you still have any questions in the comments below.

You may also like:

100 PowerShell cmdlets download free

100 POWERSHELL CMDLETS E-BOOK

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