Find a lost file anywhere on your PC with PowerShell
Find a lost file with PowerShell: run Get-ChildItem -Recurse with its name. It checks every folder on your drives and lists each match with its full path.
Windows search often misses files outside your usual folders. If you know the file’s name, PowerShell can check every folder on the drive.
Search every drive for the file name
Get-ChildItem with -Recurse looks in every folder on a drive, not just the ones Windows search indexes.
Open PowerShell and run this, with your file’s name in place of report.pdf:
Get-ChildItem C:\, D:\ -Filter report.pdf -Recurse -File -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime
- It looks in every folder on C: and D: and lists each match with its full path and the date it last changed.
- On a full drive it can take a few minutes. It’s done when the prompt comes back.
-ErrorAction SilentlyContinuehides the “access denied” errors from system folders you can’t open anyway.- Only have a C: drive? Leave out
, D:\.
Every option is in Microsoft’s Get-ChildItem reference.
Don’t know the exact name?
A * wildcard stands in for the part of the name you don’t remember.
Put * around the part you remember. Case doesn’t matter:
Get-ChildItem C:\, D:\ -Filter *report* -Recurse -File -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime
Or find files of one type that changed in the last week, here PDFs:
Get-ChildItem C:\, D:\ -Filter *.pdf -Recurse -File -ErrorAction SilentlyContinue |
Where-Object LastWriteTime -gt (Get-Date).AddDays(-7) |
Select-Object FullName, LastWriteTime
Search your own folders first
Most lost files are somewhere in your own folders: Downloads, Desktop, Documents. Search there first. It takes seconds instead of minutes:
Get-ChildItem $env:USERPROFILE -Filter report.pdf -Recurse -File -ErrorAction SilentlyContinue |
Select-Object FullName, LastWriteTime
Open the folder it’s in
This finds the first match and opens File Explorer with the file selected:
$found = Get-ChildItem C:\, D:\ -Filter report.pdf -Recurse -File -ErrorAction SilentlyContinue |
Select-Object -First 1
explorer.exe "/select,$($found.FullName)"
Search inside text files for a word
Remember a word in the file but not its name? Select-String reads text files and lists the ones that contain it:
Get-ChildItem $env:USERPROFILE -Filter *.txt -Recurse -File -ErrorAction SilentlyContinue |
Select-String -Pattern invoice -List |
Select-Object Path
Change *.txt to *.csv, *.log or *.ps1 for other plain-text files. Word and PDF files store their text in a format it can’t read.