logo
search
SharePoint Document Issues

How to Find SharePoint Folders by Keyword Using PnP PowerShell

Partner EditorPartner Editor Sep 27, 2026 869 views

Question details

The user requires a PowerShell-based solution to search across SharePoint Online sites and identify document library folders that contain a specific keyword in their name.

How to Find SharePoint Folders by Keyword Using PnP PowerShell
Product
SharePoint Online / PnP PowerShell
Device & OS
not provided
Scenario
Locating specific document folders across multiple SharePoint sites based on a target keyword (e.g., EMP) and compiling the results.
Observed behavior
The user needs to retrieve a list of folders, including details like name, creation date, item count, and relative URL, and export or filter them to isolate folders containing the keyword.
Before you start

Ensure you have SharePoint Administrator privileges and that the latest version of the PnP.PowerShell module is installed on your system before executing tenant-wide scripts.

Solution 1Recommended

Use PnP PowerShell to Retrieve and Filter Folders

Deploy a PnP PowerShell script to iterate through sites and document libraries, extracting folder properties for keyword filtering.

This approach utilizes the Get-PnPFolder cmdlet to programmatically traverse document libraries in SharePoint Online. Extracting key properties such as Name, TimeCreated, ItemCount, and ServerRelativeUrl allows you to effectively track down the required folders.

You can either filter the data directly within the PowerShell console or export the entire dataset to a CSV file for manual filtering in a spreadsheet application.

1
Install and Connect to PnP PowerShell

Open your PowerShell console as an Administrator. Run 'Install-Module -Name PnP.PowerShell' if you haven't already. Then, connect to your SharePoint environment using 'Connect-PnPOnline -Url https://yourtenant.sharepoint.com/sites/yoursite -Interactive'.

2
Retrieve Folders from Document Libraries

Set up a loop for your target document libraries. Inside the loop, run '$Folders = Get-PnPFolder -List $ListName' to retrieve all folder objects within the specified list.

3
Select Required Folder Properties

Format the retrieved data by piping it to Select-Object. Use the command '$Folders | Select-Object Name, TimeCreated, ItemCount, ServerRelativeUrl' to isolate the necessary attributes.

4
Filter by Keyword and Export

To find a specific keyword like EMP, append a Where-Object filter: 'Where-Object { $_.Name -match "EMP" }'. To export the results for sharing, pipe the final output to 'Export-Csv -Path C:\Folders.csv -NoTypeInformation'.

Use PnP PowerShell to Retrieve and Filter Folders
Exporting for Non-Technical Stakeholders: Exporting the data to a CSV file is highly recommended if you need to share the results with team members who do not use PowerShell. It allows them to apply their own keyword filters easily using spreadsheet software.
Free Microsoft Office alternative

View and Filter Exported SharePoint Data with WPS Office

After exporting your SharePoint folder data to a CSV using PowerShell, you need a robust spreadsheet application to filter and analyze the results. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office, perfect for managing your exported reports.

Fully compatible with Microsoft Excel (.xlsx, .csv) formats for seamless data reviewLightweight and fast, effortlessly opening large exported PowerShell data logsAdvanced filtering and sorting tools to quickly locate keyword-specific foldersFree to use with a familiar, easy-to-navigate interface that requires no learning curve
microsoft office alternative - wps office

Frequently Asked Questions

Can I search for multiple keywords in the folder names simultaneously?

Yes, you can modify the Where-Object filter in your PowerShell script to include multiple conditions using regular expressions. For example, using '$_.Name -match "EMP|HR|FIN"' will return folders containing any of those three keywords.

Do I need site collection admin rights to run this script across all sites?

Yes, to loop through multiple sites and document libraries across a SharePoint tenant, the account executing the script must possess SharePoint Administrator permissions or be listed as a Site Collection Administrator for each target site.

Why is Get-PnPFolder not returning all items in my large library?

For extremely large document libraries, you may encounter the SharePoint list view threshold limit (typically 5,000 items). To bypass this, you may need to adjust your PowerShell script to process items in batches or utilize CAML queries for targeted retrieval.