You need a complete list of all files and folders stored in your OneDrive for Business account, including file size, last modified date, and sharing status. OneDrive does not include a built-in export button for this data. This article explains how to generate a file inventory using PowerShell scripts and cloud-based reporting tools.
Without an inventory, you cannot easily audit storage usage, identify stale files, or check for overshared documents. The methods covered here work for both individual user accounts and tenant-wide reporting.
You will learn the exact PowerShell commands to export a CSV file containing file metadata, how to run the script in Windows PowerShell or the Microsoft 365 admin center, and how to interpret the results in Excel.
Key Takeaways: Exporting a OneDrive File Inventory
- Get-PnPFolderItem -FolderSiteRelativeUrl: PowerShell cmdlet that retrieves all files and subfolders in a specified OneDrive folder and outputs metadata to a CSV file.
- Microsoft 365 admin center > Reports > Usage > OneDrive: Built-in dashboard that shows per-user file counts and storage usage, exportable as a CSV report.
- SharePoint PnP PowerShell module: Required for running the inventory script; install with
Install-Module PnP.PowerShellin an elevated PowerShell session.
What a OneDrive File Inventory Contains and Why It Matters
A file inventory is a structured list of every item in your OneDrive account. The typical export includes the file name, file path, file size in bytes, last modified date, last modified by user, and sharing status. This data helps you answer specific questions about your storage.
You can identify files that have not been modified in over a year and decide whether to archive or delete them. You can find documents shared with external users and verify that sharing permissions are appropriate. You can also calculate total storage consumption per user across your organization.
The export is a plain CSV file. You open it in Excel, filter columns, sort by size or date, and create pivot tables. No special software is required beyond Excel or any spreadsheet application that reads CSV.
Before you start, you need the following prerequisites:
- Windows 10 or Windows 11 with PowerShell 5.1 or later installed.
- SharePoint PnP PowerShell module installed on your machine.
- Global admin or SharePoint admin role in Microsoft 365 to access all user OneDrive sites.
- OneDrive URLs for the accounts you want to inventory. The format is
https://.-my.sharepoint.com/personal/ _ _com
Steps to Export a OneDrive File Inventory Using PowerShell
This method exports the complete file list for a single OneDrive account. You can repeat the script for each user or use a loop to process multiple accounts in one run.
- Open PowerShell as Administrator
Right-click the Start button and select Windows PowerShell Admin or Terminal Admin. Confirm the User Account Control prompt. - Install the PnP PowerShell module if not already installed
RunInstall-Module PnP.PowerShell -Scope CurrentUser. Press Y when prompted to install from PSGallery. This module provides the cmdlets needed to connect to OneDrive and retrieve file data. - Connect to your tenant
RunConnect-PnPOnline -Url https://. Replace-admin.sharepoint.com -Interactive <tenant>with your Microsoft 365 tenant name. A browser window opens. Sign in with your admin credentials. This connection allows the script to access all site collections in the tenant. - Get the OneDrive site URL for the target user
RunGet-PnPTenantSite | Where-Object {$_.Url -like "-my.sharepoint.com"} | Select-Object Url. This lists all OneDrive site URLs. Copy the URL for the user you want to inventory. - Connect to the specific OneDrive site
RunConnect-PnPOnline -Url. Sign in again if prompted. You are now connected directly to that user’s OneDrive.-Interactive - Export the file inventory to CSV
Run the following script:$items = Get-PnPFolderItem -FolderSiteRelativeUrl "/Documents" -ItemType File
$items | Select-Object Name, ServerRelativeUrl, Length, TimeLastModified, ModifiedBy | Export-Csv -Path "C:\OneDriveInventory.csv" -NoTypeInformation
Replace/Documentswith the folder path you want to scan. Use/for the root. The CSV file is saved to your local drive. Open it in Excel to review the data.
To inventory multiple users, wrap the steps in a foreach loop. Store the OneDrive URLs in a text file and iterate through them. Append results to a single CSV file using -Append in the Export-Csv cmdlet.
Common Issues When Exporting a OneDrive File Inventory
PowerShell returns an access denied error
This error occurs when the account used to connect does not have SharePoint admin permissions or when the OneDrive site is not provisioned. Verify that your account has the SharePoint admin role in the Microsoft 365 admin center. If the site is not provisioned, the user must sign in to OneDrive at least once to create the site.
The CSV file is empty or contains only headers
The Get-PnPFolderItem cmdlet with -ItemType File returns only files in the specified folder, not subfolders. If the target folder has no files directly inside it, the output is empty. Use -ItemType Folder first to list subfolders, then loop through each subfolder to collect all files.
The script runs for a long time on large OneDrive accounts
OneDrive accounts with more than 10,000 files can cause the script to take several minutes. Add the -Recursive parameter to Get-PnPFolderItem to include all nested folders in one call. This reduces the number of API requests and speeds up the export.
Alternative Methods for Exporting OneDrive File Inventory
If you cannot use PowerShell, two other methods provide partial inventory data.
Microsoft 365 admin center usage reports
Go to the Microsoft 365 admin center, select Reports, then Usage, then OneDrive. This dashboard shows per-user file count, active file count, and storage used. Click Export to download a CSV file. This report does not include individual file names or sharing status.
Microsoft 365 compliance center data inventory
The compliance center provides a data inventory report that lists OneDrive files containing sensitive information. This report uses content search and includes file location, last modified date, and classification labels. It is limited to files matched by the search query and does not cover all files.
| Item | PowerShell Script | Admin Center Report |
|---|---|---|
| Data granularity | Individual file names, sizes, dates, and sharing status | Aggregate counts per user only |
| Sharing details | Included with additional cmdlets | Not included |
| Ease of use | Requires PowerShell knowledge | No scripting required |
| Scope | Single user or all users with a loop | All users at once |
| File count limit | No limit, but large sets take time | Up to 10,000 rows per export |
The PowerShell method gives you full control over the data columns and scope. The admin center report is faster for a high-level overview but lacks detail.
After you export the inventory, open the CSV in Excel. Use filters to sort by file size descending to find the largest files. Use the last modified column to identify files older than 12 months. Create a pivot table to count files by folder path for a storage breakdown.
For ongoing monitoring, schedule the PowerShell script using Windows Task Scheduler. Run it weekly and save the output to a shared folder. Compare week-over-week changes to track growth or detect unusual file additions.