How to Find and Delete Empty Folders in SharePoint Online
Question details
SharePoint Online administrators need to locate and remove folders that contain no files or subfolders to keep document libraries organized.

- 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.
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.
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.
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.
Authenticate to your environment by executing 'Connect-PnPOnline -Url https://yourtenant-admin.sharepoint.com -Interactive'. Enter your administrator credentials when prompted.
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.
For a robust, production-ready script and advanced developer assistance, post your specific requirements in the Microsoft Q&A SharePoint Development community.

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. Download WPS Office: Visit the official WPS website and download the free installer for your operating system.
- 2. Install the Suite: Run the setup file and follow the simple on-screen instructions to install the software in minutes.
- 3. Open and Edit Documents: Launch WPS Office to instantly open, edit, and save your existing Microsoft Office files with perfect compatibility.

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.




