SharePoint Version Cleanup Across Sites with PowerShell and CSV
Use a CSV to scope SharePoint version cleanup without turning an unchecked site list into a bulk deletion job. This guide separates inventory, impact analysis, approval and native library trimming.
Prepare a reviewed site and library inventory
Use a CSV with exactly SiteURL and LibraryName columns to identify the libraries approved for review. Keep this inventory separate from an instruction to delete versions. Include the data owner, retention decision and report location in your change record.
SiteURL,LibraryName
https://contoso.sharepoint.com/sites/Operations,Documents
Connect with the current management shell
Install or update Microsoft.Online.SharePoint.PowerShell using Microsoft’s setup instructions, then connect to the tenant admin endpoint with an authorized SharePoint administrator. Choose a host supported by that module. There is no need to uninstall unrelated SharePoint modules as a prerequisite.
Import-Module Microsoft.Online.SharePoint.PowerShell
Connect-SPOService -Url 'https://contoso-admin.sharepoint.com'
$libraries = Import-Csv -LiteralPath '.\libraries.csv'
$libraries | Select-Object SiteURL, LibraryName
Check every URL, library name and permission before submitting jobs. Duplicate rows can submit duplicate work. A successful CSV import does not prove that those libraries exist.
Report before selecting a trimming policy
Generate Microsoft’s version storage report for the selected scope and perform its documented impact analysis. Give each report a distinct destination in a library the administrator can write to. Wait for completion before using the results; report creation is asynchronous.
Review retention policies, records requirements, holds and recoverability with the content owner. Do not assume that keeping one historical entry preserves the same recovery capability as version history. Save the approved CSV and projected impact with the change ticket.
Apply a library-scoped decision
Use the native New-SPOListFileVersionBatchDeleteJob command for an individually approved library, choosing its documented count, age or existing-policy parameter set. Keep submission, progress tracking and outcome reporting as separate steps. Do not blindly loop a destructive job across every discovered site.
Microsoft’s trim workflow permanently deletes affected versions outside normal recycle-bin recovery. Confirm an appropriate independent backup and restore process before running it. A queued job is not a completed job or proof of reclaimed capacity.
The earlier recursive PnP deletion script has been retired here. For separate PnP tasks, use a tenant-owned Entra application and current authentication instructions rather than the removed shared PnP Management Shell application.
Practical checks and next steps
Pilot one library, retain the approved inventory and report, and check the completed job before expanding the change. Access to an administrator role is not approval to delete every historical version.
Explore Microsoft 365, PowerShell & Automation for related guides.
Reference 1 Reference 2 Reference 3 Reference 4 Reference 5
Content review: November 24, 2026. Reviewed the stated scope, guidance and source references; tenant, hardware and production changes were not executed as part of this editorial review. Original publication date retained.