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 .txtreport?.docx– Matches report1.docx, reportA.docx, but not report10.docxfile[123].txt– Matches file1.txt, file2.txt, or file3.txtfile[0-9].txtmatches 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:

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
| Operator | Description | Example |
|---|---|---|
-like | Wildcard matching | $_.Name -like "*.doc" |
-notlike | Inverse wildcard | $_.Name -notlike "temp*" |
-match | Regex matching | $_.Name -match "\d{3}" |
-eq | Exact 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" -RecurseKey features:
-Recurseparameter 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.zip2025_backup.zipimportant_data_backup.zipbackup_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:
| Pattern | Matches | Doesn’t Match |
|---|---|---|
file?.txt | file1.txt, file2.txt, fileA.txt | file10.txt, file.txt, fileAB.txt |
data?.csv | data1.csv, dataX.csv | data10.csv, data.csv |
log??.txt | log01.txt, logAB.txt | log1.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:
| Pattern | Matches | Use Case |
|---|---|---|
[0-9] | Any single digit (0-9) | Numbered files |
[a-z] | Any lowercase letter | Lettered versions |
[A-Z] | Any uppercase letter | Capitalized codes |
[aeiou] | Specific characters only | Custom 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:
Bijay Kumar is an esteemed author and the mind behind PowerShellFAQs.com, where he shares his extensive knowledge and expertise in PowerShell, with a particular focus on SharePoint projects. Recognized for his contributions to the tech community, Bijay has been honored with the prestigious Microsoft MVP award. With over 15 years of experience in the software industry, he has a rich professional background, having worked with industry giants such as HP and TCS. His insights and guidance have made him a respected figure in the world of software development and administration. Read more.