You need a complete list of files in a SharePoint document library, including metadata like file name, size, modified date, and author. Manually copying file names from a browser is slow and error-prone. SharePoint provides built-in export tools that let you download this data as a CSV file. This article explains how to export a library file inventory to CSV using the Export to Excel feature and PowerShell for larger or more detailed inventories.
Key Takeaways: Exporting SharePoint Library File Inventory to CSV
- Library > Export to Excel: Downloads a .iqy file that opens in Excel, which can be saved as CSV. Quickest method for standard metadata columns.
- PowerShell with PnP.PowerShell: Exports all files and custom metadata to CSV. Best for libraries with thousands of files or advanced column requirements.
- Create a view before exporting: Filtering and sorting the library view ensures the exported data includes only the files and columns you need.
How the Export to Excel Feature Works in SharePoint Libraries
SharePoint libraries include a built-in Export to Excel command that exports the current view to a .iqy file. An .iqy file is a web query that opens in Excel and loads the library data as a live connection. From Excel, you can save the data as a CSV file. This method works for libraries with up to 5000 items due to SharePoint list view thresholds. You must have at least Read permissions on the library. The exported data includes all columns visible in the current library view, including custom metadata columns.
Steps to Export a Library File Inventory to CSV Using Export to Excel
- Open the document library in SharePoint
Navigate to the SharePoint site and open the document library that contains the files you want to export. - Create or select a view with the columns you need
Click the library view dropdown near the top-right and choose an existing view or select Edit current view to add or remove columns. Include columns like Name, Modified, Modified By, File Size, and any custom metadata columns. - Apply filters if needed
Use column filters to limit the exported data to specific file types, date ranges, or other criteria. Only visible files will be exported. - Click Export to Excel
In the command bar at the top of the library, click Export and then select Export to Excel. If you do not see the Export button, click the ellipsis (…) on the command bar. - Open the .iqy file in Excel
Your browser will download an .iqy file. Open it in Excel. If prompted, click Enable to allow the data connection. - Save the Excel data as CSV
In Excel, review the imported data. Click File > Save As and choose CSV UTF-8 (Comma delimited) or CSV (Comma delimited) as the file type. Click Save.
Steps to Export a Library File Inventory to CSV Using PowerShell
For libraries with more than 5000 items or when you need to export data from multiple libraries, use PowerShell with the PnP.PowerShell module. This method bypasses the list view threshold and supports all columns.
- Install the PnP.PowerShell module
Open PowerShell as an administrator and run:Install-Module PnP.PowerShell -Scope CurrentUser. If prompted, press Y to install from PSGallery. - Connect to SharePoint
Run:Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive. Replace the URL with your site URL. Sign in with your Microsoft 365 account. - Export library items to CSV
Run the following script, replacing the library name and output path:$items = Get-PnPListItem -List "Shared Documents" -PageSize 500$items | Export-Csv -Path "C:\export\library-inventory.csv" -NoTypeInformation
This exports all items from the library including default columns like Title, Modified, Created, and ID. - Include specific columns in the export
To include custom columns, use:$items = Get-PnPListItem -List "Shared Documents" -Fields "FileLeafRef","FileSizeDisplay","Editor","Modified","CustomColumn1"$items | Select-Object -Property FileLeafRef, FileSizeDisplay, Editor, Modified, CustomColumn1 | Export-Csv -Path "C:\export\library-inventory.csv" -NoTypeInformation
Common Issues When Exporting Library Inventories
Export to Excel button is missing or grayed out
The Export to Excel command is not available in all SharePoint library views. If the button is missing, switch to a standard view like All Documents. The command also requires that the library does not have custom scripting disabled at the tenant level. Contact your SharePoint admin to check tenant settings.
Exported CSV shows only file names and no metadata
This happens when the current library view does not include the metadata columns you expect. Before exporting, edit the view and add the columns you need. The Export to Excel command exports exactly what is visible in the view.
PowerShell export fails with permission error
The account used to connect to SharePoint must have at least Read permissions on the site and library. If you receive an access denied error, verify your permissions or use a different account that has site collection administrator rights.
CSV file contains extra columns or blank cells
When using PowerShell, the default export includes all internal fields. Use the Select-Object cmdlet to specify only the columns you want. For blank cells, check if the column has a default value in SharePoint or if the item simply has no value for that field.
| Item | Export to Excel | PowerShell with PnP.PowerShell |
|---|---|---|
| Maximum items | 5000 items (list view threshold) | No practical limit (uses server-side paging) |
| Required permissions | Read on library | Read on site or library |
| Custom metadata columns | Only if included in the view | All columns including hidden fields |
| Output format | .iqy then save as CSV in Excel | Direct CSV file |
| Automation possible | No, manual steps required | Yes, script can be scheduled |
You can now export a complete file inventory from any SharePoint library using either the built-in Export to Excel feature or PowerShell. For a one-time export of a small library, the Export to Excel method works quickly. For recurring exports or libraries with many items, use the PowerShell script and save it for reuse. To refine your export further, explore the Get-PnPListItem parameters to filter by folder or content type.