SharePoint Document Issues

How to Count Files and Folders in a SharePoint Online Site

Ayan MasoodAyan Masood Nov 2, 2026 869 views

Question details

The user needs a complete and accurate count of all files and folders across a SharePoint Online site or specific document libraries.

How to Count Files and Folders in a SharePoint Online Site
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.
Before you start

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.

Solution 1Recommended

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.

1
Install the PnP PowerShell Module

Open PowerShell as an Administrator and execute 'Install-Module -Name PnP.PowerShell' to download and install the necessary cmdlets.

2
Connect to Your SharePoint Site

Run the command 'Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive' and log in with your administrative credentials.

3
Run the Counting Script

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.

4
Export the Data to CSV

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.

Use PnP PowerShell to Enumerate and Count Files
PowerShell Execution Policy: If you encounter errors running scripts, you may need to adjust your execution policy by running 'Set-ExecutionPolicy RemoteSigned' in your elevated PowerShell window.
Free Microsoft Office alternative

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. 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite on your computer.
  2. 2. Open Your Documents: Launch WPS Office and open the documents you have synced or downloaded from your SharePoint document libraries.
  3. 3. Edit and Save Seamlessly: Edit your files using the familiar tool ribbon and save them with strict Microsoft Office format compatibility.
Fully compatible with Microsoft Word, Excel, and PowerPoint formats (.docx, .xlsx, .pptx).Lightweight installation that runs smoothly even on older devices.Familiar user interface for seamless migration without any learning curve.Built-in PDF editing tools for comprehensive desktop document management.
microsoft office alternative - wps office

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.