How to Find PDF Files by Name and Content with PowerShell
Question details
The user needs a method to search local drives and OneDrive directories for PDF files containing specific text in their names and contents, and export the resulting file paths.
- Product
- PowerShell
- Device & OS
- Windows
- Scenario
- Locating specific PDF documents across multiple directories based on filename and internal text keywords.
- Observed behavior
- The user is seeking a script or solution to automate the search process and extract full paths, facing challenges with native PowerShell's inability to easily parse PDF text content.
Ensure you have administrative privileges to run PowerShell scripts and that the directories you intend to search, including synced OneDrive folders, are fully accessible.
Use PowerShell Cmdlets and Third-Party Modules
Use native PowerShell commands to search by filename, and rely on specialized modules or community guidance for deep content extraction.
Native PowerShell commands like Select-String work well for plain text, but extracting text from PDF files requires third-party modules (like PSPDFKit or iTextSharp) because PDFs are complex binary files.
Click the Start menu, type 'PowerShell', right-click on Windows PowerShell, and select 'Run as Administrator'.
Use the Get-ChildItem cmdlet to locate PDFs by name across local and OneDrive paths. Example: Get-ChildItem -Path 'C:\YourLocalPath', 'C:\Users\Name\OneDrive' -Filter '*keyword*.pdf' -Recurse
To read the actual text inside the PDFs, install and import a specialized module like PSPDFKit. You can integrate this into a Foreach loop to check the extracted text against your keywords.
Once your script filters the files, pipe the resulting file paths into Export-Csv or Out-File to save your list. Example: ... | Select-Object FullName | Export-Csv -Path 'C:\results.csv'
Search and Manage PDF Files Effortlessly with WPS Office
Instead of writing complex and error-prone PowerShell scripts to find your files, you can use the built-in document management features in WPS Office. It allows you to quickly locate PDFs and other documents across your device and cloud storage.
- 1. Launch WPS Office: Open the WPS Office desktop application on your computer.
- 2. Use the Search Bar: Navigate to the Home tab and locate the global search bar at the top of the interface.
- 3. Enter Your Keywords: Type the name or partial name of the PDF file you are looking for.
- 4. Filter by File Type: Use the built-in filters to narrow down the search results specifically to PDF documents, allowing you to instantly find and open your file.

Frequently Asked Questions
Why can't native PowerShell read PDF content directly?
Native PowerShell cmdlets like Select-String are designed to read plain text files (such as TXT or CSV). Since PDFs are complex binary files with rich formatting, PowerShell requires specialized third-party libraries to extract and parse the internal text.
How do I search my OneDrive folder using PowerShell?
You can search your OneDrive folder by specifying its local sync directory (typically 'C:\Users\YourUsername\OneDrive') as the -Path parameter in your Get-ChildItem command. Ensure that the files are downloaded locally if you intend to scan their contents.
How can I easily export my PowerShell search results to a file?
You can append the Out-File or Export-Csv cmdlets to the end of your command pipeline. For example, adding '| Export-Csv -Path C:\SearchResults.csv -NoTypeInformation' will create a spreadsheet containing your matched file paths.




