How to Count Files and Folders in a SharePoint Online Site
Question details
The user needs a complete and accurate count of all files and folders across a SharePoint Online site or specific document libraries.

- Product
- SharePoint Online
- Device & OS
- not provided
- Scenario
- Auditing site storage, reviewing document library usage, or generating file statistics where default administrative reports fall short.
- Observed behavior
- SharePoint Online's built-in Usage report fails to provide a complete and fully accurate count of all files and folders across the site.
Ensure you have SharePoint Administrator or Site Collection Administrator permissions, and verify that the latest version of the PnP PowerShell module is installed on your computer.
Use PnP PowerShell to Enumerate and Count Files
Utilize a custom PnP PowerShell script to iterate through document libraries, retrieve an accurate item count, and export the comprehensive results to a CSV file.
Since the default Site Usage report in SharePoint Online may exclude certain system files or suffer from reporting delays, running a PnP PowerShell script provides real-time, granular control over data collection.
This method requires you to connect directly to the site collection and loop through the available lists and libraries to tally the items.
Open PowerShell as an Administrator and execute 'Install-Module -Name PnP.PowerShell' to download and install the necessary cmdlets.
Run the command 'Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive' and log in with your administrative credentials.
Use the 'Get-PnPList' cmdlet to retrieve all document libraries. Set up a loop to iterate through each library, reading the '$list.ItemCount' property to count files and folders.
Pipe your gathered list variables into the 'Export-Csv -Path "C:\temp\SharePointCounts.csv" -NoTypeInformation' cmdlet to save the final report to your local drive.

Looking for a Lightweight Office Suite to Manage Your Documents?
While SharePoint and PowerShell handle complex server-side administration, WPS Office provides a free, fast, and highly compatible desktop alternative to Microsoft Office for editing and managing your everyday documents downloaded from SharePoint.
- 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite on your computer.
- 2. Open Your Documents: Launch WPS Office and open the documents you have synced or downloaded from your SharePoint document libraries.
- 3. Edit and Save Seamlessly: Edit your files using the familiar tool ribbon and save them with strict Microsoft Office format compatibility.

Frequently Asked Questions
Why does the SharePoint Site Usage report show inaccurate file counts?
The built-in Site Usage report may experience data processing delays, or it may exclude hidden files, specialized system folders, and specific library configurations, leading to discrepancies compared to the actual item count.
Do I need Global Admin rights to run the PnP PowerShell script?
You do not necessarily need Global Admin rights, but you do need at least SharePoint Administrator rights or Site Collection Administrator permissions for the specific site you are querying.
Can I count files in specific SharePoint document libraries instead of the entire site?
Yes, you can modify your PnP PowerShell script to target a specific library by using the 'Get-PnPList -Identity "Library Name"' cmdlet instead of retrieving all site lists.
Is there a way to count files without using PowerShell?
Yes. You can manually navigate to the 'Site Contents' page via the settings gear icon. This page displays the item count for each individual document library and list, though you will have to manually tally the numbers for a site-wide total.




