logo
search
SharePoint Document Issues

How to Find and Delete Empty Folders in SharePoint Online

Natalie TaylorNatalie Taylor Oct 7, 2026 870 views

Question details

SharePoint Online administrators need to locate and remove folders that contain no files or subfolders to keep document libraries organized.

How to Find and Delete Empty Folders in SharePoint Online
Product
SharePoint Online
Device & OS
not provided
Scenario
Managing and organizing document libraries by removing unused or empty folders in bulk.
Observed behavior
Folders that are entirely empty remain in the library, creating clutter and requiring an automated PowerShell method to safely find and delete them.
Before you start

Ensure you have SharePoint Administrator permissions and the appropriate PowerShell modules installed. It is highly recommended to run and test any deletion scripts on a non-production library first to prevent accidental data loss.

Solution 1Recommended

Use SharePoint Online PowerShell to Automate Deletion

Utilize a PowerShell script to scan document libraries for empty folders and remove them automatically.

PowerShell provides a robust way for administrators to interact with SharePoint Online. By utilizing modules like PnP PowerShell, you can iterate through folders in a document library, check their item count, and seamlessly delete those that are completely empty.

1
Install the PnP PowerShell Module

Open your PowerShell console as an administrator and run the command 'Install-Module -Name PnP.PowerShell' to ensure you have the necessary tools to manage SharePoint Online.

2
Connect to SharePoint Admin Center

Authenticate to your environment by executing 'Connect-PnPOnline -Url https://yourtenant-admin.sharepoint.com -Interactive'. Enter your administrator credentials when prompted.

3
Identify and Delete Empty Folders

Formulate a script to loop through the targeted Document Library, identifying folders where the ItemCount property equals zero, and use the 'Remove-PnPFolder' command to delete them.

4
Consult the SharePoint Development Community

For a robust, production-ready script and advanced developer assistance, post your specific requirements in the Microsoft Q&A SharePoint Development community.

Use SharePoint Online PowerShell to Automate Deletion
Test Before Execution: Always test your PowerShell script in a staging or non-production environment before running it on live document libraries to confirm permissions and verify that only the intended empty folders are deleted.
Free Microsoft Office alternative

Need a Lightweight Alternative for Document Management? Try WPS Office

While managing complex SharePoint server environments requires specialized tools and scripts, your daily document creation and editing doesn't have to be complicated. WPS Office is a highly compatible, free, and lightweight alternative to Microsoft Office. It seamlessly opens Word, Excel, and PowerPoint files, making it easier for your team to collaborate and manage local or cloud documents without heavy overhead.

  1. 1. Download WPS Office: Visit the official WPS website and download the free installer for your operating system.
  2. 2. Install the Suite: Run the setup file and follow the simple on-screen instructions to install the software in minutes.
  3. 3. Open and Edit Documents: Launch WPS Office to instantly open, edit, and save your existing Microsoft Office files with perfect compatibility.
Fully compatible with Microsoft Office formats (.docx, .xlsx, .pptx).Lightweight installation with incredibly fast document loading speeds.Familiar, intuitive user interface that requires no learning curve.Built-in cloud support for seamless document syncing and sharing.
microsoft office alternative - wps office

Frequently Asked Questions

Can I recover folders deleted by a PowerShell script in SharePoint?

Yes, folders deleted via PowerShell are typically moved to the SharePoint site's Recycle Bin. A Site Owner or Administrator can restore them from the Recycle Bin within 93 days.

Do I need special permissions to run PowerShell scripts on SharePoint Online?

Yes, you must have SharePoint Administrator or Global Administrator privileges to connect via PowerShell and execute deletion commands across your organization's site collections.

Why can't I just delete empty folders from the SharePoint web interface?

You can delete empty folders manually via the SharePoint web interface. However, for large document libraries containing hundreds or thousands of folders, an automated PowerShell script saves significant time and reduces manual effort.

Where can I find reliable PowerShell scripts for SharePoint?

Microsoft's official documentation and the Microsoft Q&A SharePoint Development community are excellent resources for finding, verifying, and requesting production-ready PnP PowerShell scripts.