-
Notifications
You must be signed in to change notification settings - Fork 0
Usage
SPSCleanVersions.ps1 is a PowerShell script tool to clean Version History in your SharePoint Tenant. Optimize your storage costs by managing major and minor versions across libraries and lists.
Requires PowerShell 7.2 or later with PSEdition Core. Installation guide.
This tool relies on the PnP.PowerShell module version 2.12.0 or later. Installation guide.
- Role: SharePoint Administrator or Global Administrator.
-
API Permissions:
Sites.FullControl.All(when using App Registration).
The script accepts its configuration from one of two mutually exclusive sources:
| Parameter | Type | Parameter Set | Description |
|---|---|---|---|
-InputJson |
string | InlineJson (default) | Inline JSON string with all configuration. Ideal for Azure Automation Runbooks. |
-ConfigFile |
string | ConfigFile | Path to a local JSON file with the same schema. Ideal for local execution and testing. |
All configuration is expressed as JSON. Supported properties:
| Property | Type | Required | Default | Description |
|---|---|---|---|---|
SiteUrls |
string[] | Yes | — | Site Collection URLs to process |
KeepMajorVersions |
integer | No | 50 |
Number of major versions to keep |
KeepMinorVersions |
integer | No | 0 |
Number of minor versions to keep |
ClientId |
string | No | — | Azure AD App Registration Client ID |
ForceDeleteOldVersions |
boolean | No | false |
Trigger batch delete of old file versions |
DryRun |
boolean | No | false |
Simulate changes without applying them |
.\SPSCleanVersions.ps1 -InputJson '{"SiteUrls":["https://contoso.sharepoint.com/sites/News"],"KeepMajorVersions":50}' -WhatIf.\SPSCleanVersions.ps1 -ConfigFile '.\Config\contoso-PROD.json'.\SPSCleanVersions.ps1 -InputJson '{"SiteUrls":["https://contoso.sharepoint.com/sites/News","https://contoso.sharepoint.com/sites/HR"],"KeepMajorVersions":50,"DryRun":true}'Set "ForceDeleteOldVersions": true to submit a batch delete job that removes old file versions exceeding the configured limits via New-PnPSiteFileVersionBatchDeleteJob.
Note: Batch delete requires delegated user context. It is automatically skipped when running in Azure Automation (Managed Identity / app-only). A warning is displayed in that case.
.\SPSCleanVersions.ps1 -InputJson '{"SiteUrls":["https://contoso.sharepoint.com/sites/News"],"KeepMajorVersions":50,"ForceDeleteOldVersions":true,"DryRun":true}'Ensure the provided credentials have access to the SharePoint Sites.
Test the script in a non-production environment before deploying it widely.
For issues or questions, please contact the script maintainer or refer to the project documentation.
Navigation
Project