PowerShell Find File: Search Files & Folders
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
To find a file in PowerShell, use the Get-ChildItem cmdlet with the -Recurse and -Filter parameters, or the Where-Object cmdlet for more complex criteria. This article explains the common commands, syntax, and examples for locating files and folders on Windows.
Why Use PowerShell to Find Files?
Windows File Explorer’s search box works, but it’s slow, limited, and often misses hidden or system files. PowerShell gives you a scriptable, precise way to search by name, extension, size, date, or content. It’s especially useful when you need to:
- Search across many folders or entire drives
- Find files modified before or after a certain date
- Locate files larger than a specific size
- Automate searches in scripts
- Search hidden or system files
Unlike the GUI, PowerShell returns results as objects, so you can easily sort, filter, export, or pipe them to other commands.
Basic Search with Get-ChildItem
The core cmdlet is Get-ChildItem (alias dir or ls). To find all files with a certain extension in a folder and its subfolders:
- Open PowerShell (Start > type “PowerShell�)
- Run:
Get-ChildItem -Path C:\ -Recurse -Filter *.log - Results show full path, name, size, and last write time
To search only the top folder (no subfolders), omit -Recurse. To include hidden files, add -Force.
Filtering by Name, Extension, and Path
The -Filter parameter is fast and accepts wildcards like * and ?. Examples:
*.pdf– all PDFsreport*.xlsx– files starting with “report� and ending .xlsxfile?.txt– file1.txt, fileA.txt, but not file10.txt
For more complex name matching, use Where-Object with the -like operator:
Get-ChildItem -Path C:\ -Recurse | Where-Object { $_.Name -like "*budget*" }
To search for a file by its full path (even if the name is unknown), use Test-Path.
Finding Files by Date, Size, or Content
PowerShell lets you filter on file properties. For example, find files modified in the last 7 days:
Get-ChildItem -Path C:\ -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-7) }
Find files larger than 1 GB:
Get-ChildItem -Path C:\ -Recurse | Where-Object { $_.Length -gt 1GB }
To search inside file contents (e.g., find files containing the word “error�), use Select-String:
Get-ChildItem -Path C:\ -Recurse -Include *.txt | Select-String -Pattern "error"
This can be slow on large drives, so narrow the path and file type first.
Common Problems and How to Avoid Them
- Access denied errors: Run PowerShell as Administrator to search protected folders (e.g., C:\Windows).
- Too many results: Use
-Filterand a specific path instead of the whole drive. - Hidden files not found: Add
-Forceto include hidden and system files. - Slow search: Avoid
-Recurseon the entire C:\ drive; target the likely folder. - Path too long: PowerShell handles long paths in most modern Windows versions, but older ones may fail. Use
\?\\prefix if needed.
If you get no results, double-check the path and wildcard syntax. Use Test-Path C:\some\file.txt to verify a single file exists.
Alternatives to PowerShell
If you prefer a GUI, Windows Search in File Explorer supports advanced queries like type:.pdf or datemodified:last week. The Command Prompt’s dir /s /b *.log is simpler but less flexible. For very large or indexed searches, Everything (a third-party tool) is faster, but PowerShell is built-in, scriptable, and free.
Frequently Asked Questions
How do I find a file by name in PowerShell?
Use Get-ChildItem -Path C:\ -Recurse -Filter filename.txt. Replace the path and filename with your own. To search the current folder, use Get-ChildItem -Recurse -Filter filename.txt.
How do I find a file containing a specific text string?
Combine Get-ChildItem with Select-String: Get-ChildItem -Path C:\ -Recurse -Include *.txt | Select-String -Pattern "search text". This searches the contents of files, not just names.
Why does Get-ChildItem not show hidden files?
By default, hidden and system files are excluded. Add the -Force parameter to include them: Get-ChildItem -Path C:\ -Recurse -Force.
How do I find files modified in the last 24 hours?
Use Get-ChildItem -Path C:\ -Recurse | Where-Object { $_.LastWriteTime -gt (Get-Date).AddDays(-1) }. Adjust the number of days as needed.
Can I search for a file without knowing its exact name?
Yes, use wildcards. For example, Get-ChildItem -Path C:\ -Recurse -Filter *report* finds any file with “report� in its name. For partial names, use * around the known part.
Is there a faster way to search than Get-ChildItem?
For large drives, the Windows Search index (via where /r in cmd or the Search box) is faster. PowerShell is more flexible and scriptable, but may be slower on huge directories. Consider narrowing the search path.
Related
Formula used
in t | Search path | - | C:\ | 0 in d | Max depth (0=all) | - | 0 | 0 in f | File name pattern | - | *.log | 0 out r | Files found | count | 0 | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.