logo
search
Others

How to Find PDF Files by Name and Content with PowerShell

Maira MehtabMaira Mehtab Sep 27, 2026 869 views

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.
Before you start

Ensure you have administrative privileges to run PowerShell scripts and that the directories you intend to search, including synced OneDrive folders, are fully accessible.

Solution 1Recommended

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.

1
Open PowerShell

Click the Start menu, type 'PowerShell', right-click on Windows PowerShell, and select 'Run as Administrator'.

2
Search by Filename

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

3
Install PDF Modules for Content Search

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.

4
Export the Results

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'

Troubleshooting PDF Modules: If you cannot find the PSPDFKit module or encounter errors, verify its exact name and installation source. For advanced scripting assistance, consider asking the Microsoft Q&A community where specialists provide guidance on PowerShell and PDF text extraction.
A Simpler Alternative

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. 1. Launch WPS Office: Open the WPS Office desktop application on your computer.
  2. 2. Use the Search Bar: Navigate to the Home tab and locate the global search bar at the top of the interface.
  3. 3. Enter Your Keywords: Type the name or partial name of the PDF file you are looking for.
  4. 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.
Instantly search for PDF files by name without writing code or scripts.Built-in global search feature helps you locate files across local folders and cloud storage.Fully compatible with standard PDF formats and all Microsoft Office file types (Word, Excel, PowerPoint).Includes a powerful suite of PDF reading, editing, and conversion tools.
QA img-9

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.