SharePoint is a robust platform used by organizations worldwide for content management, collaboration, and data storage. One of its key features is versioning, which automatically creates a new version of a file or list item each time it is modified. This version history enables users to track changes, restore previous versions, and maintain data integrity.
However, over time, storing multiple versions of files and list items can lead to storage bloat and decreased performance. Deleting unnecessary or outdated versions becomes essential to free up space, improve performance, and manage costs effectively.
Let’s explore:
- What SharePoint versioning is and why it matters.
- The benefits and drawbacks of deleting old versions.
- Who uses version deletion and why.
- Best practices for efficient version management.
- Sample PowerShell scripts for both SharePoint Online and On-Premises environments.
- A comparison of different implementation methods, including manual, automated, and third-party solutions.
By the end of this guide, you’ll have a clear understanding of how to clean up SharePoint versions effectively while ensuring the stability and security of your data.
✅ What is Versioning in SharePoint?
Versioning in SharePoint is the automated creation of multiple iterations of a file or list item whenever changes are made. This feature allows users to review previous modifications, revert to earlier versions, and maintain a history of the document’s evolution.
There are two main types of versioning in SharePoint:
- Major Versions (e.g., 1.0, 2.0, 3.0):
- Major versions represent significant changes or published states of a document.
- They are typically used in libraries where content approval or official document versions are required.
- Each time you save a document, a new major version is created, making it easy to track the progression of the file.
- Minor Versions (e.g., 1.1, 1.2, 1.3):
- Minor versions track interim changes or drafts.
- These are commonly used when content approval is enabled, allowing users to save drafts before publishing.
- Minor versions are only visible to users with edit permissions, making them useful for collaborative content reviews.
💡 Why Do You Need to Delete Versions?
While SharePoint’s versioning feature is beneficial, it can lead to storage inefficiencies and performance degradation over time. Here’s why you might need to delete older versions:
- 🛠️ Storage Management:
- Each version of a file or list item takes up storage space.
- Over time, large libraries with hundreds of versions can consume gigabytes of storage, which can push your SharePoint Online environment closer to its quota.
- Deleting old versions reduces storage usage and ensures you are making the most of your allocated space.
- ⚙️ Performance Optimization:
- Excessive versions can slow down query and retrieval performance.
- Libraries with thousands of files and multiple versions can lead to sluggish loading times, impacting user experience.
- Cleaning up old versions makes SharePoint libraries more responsive.
- 🔍 Data Hygiene:
- Removing outdated or irrelevant versions keeps your document library clean and organized.
- It also prevents confusion caused by unnecessary historical data.
- 💰 Cost Management:
- In SharePoint Online, you pay for additional storage beyond your allocated quota.
- By deleting old versions, you can reduce storage consumption and potentially save on storage costs.
🧑💻 Who Uses Version Deletion and What Applications Need It?
Version deletion is commonly performed by SharePoint administrators, content managers, and compliance officers. Here’s why different groups may need to clean up versions:
- SharePoint Administrators:
- Admins are responsible for managing SharePoint storage and performance.
- Regularly deleting old versions helps them prevent performance issues and keep libraries running smoothly.
- They also need to enforce retention policies by removing outdated versions.
- Content Managers:
- Content managers oversee large document libraries with frequent updates.
- To maintain a clean content repository, they may delete irrelevant versions while keeping a few recent ones.
- Compliance Officers:
- In organizations with strict compliance requirements, officers need to remove versions that no longer comply with data retention policies.
- Deleting old versions ensures that only current, valid data is retained.
✅ Applications that require version cleanup:
- Document Libraries: Large libraries with multiple contributors tend to accumulate significant version history.
- Project Lists: Task or project lists with regular updates can create multiple item versions that need periodic cleanup.
- SharePoint Online and On-Premises Admin Centers: Admins use PowerShell scripts or third-party tools to bulk delete versions.
⚙️ Prerequisites Before Deleting Versions
Before you start deleting versions, ensure you meet the following requirements:
- Permissions:
- You need Full Control or Site Collection Administrator permissions.
- Without the correct permissions, you won’t be able to modify or delete versions.
- Backup Your Data:
- Always create a backup of your document libraries or lists before performing bulk version deletions.
- This allows you to restore the data in case of accidental deletions.
- PowerShell Modules:
- For SharePoint Online, install: powershellCopyEdit
Install-Module -Name "PnP.PowerShell" -Scope CurrentUser
- For SharePoint On-Premises, ensure you have the SharePoint Management Shell installed.
- For SharePoint Online, install: powershellCopyEdit
- Audit Versioning Settings:
- Review the versioning settings in SharePoint to determine how many versions you want to keep.
- In many cases, organizations retain 5-10 major versions and delete the rest.
🚦 Best Practices for Deleting Versions
- Define a Retention Policy:
- Establish a policy to automatically delete versions older than a certain date.
- This reduces the need for manual intervention and ensures consistent version cleanup.
- Use PowerShell for Bulk Deletion:
- PowerShell scripts allow you to delete versions in bulk, making the process faster and more efficient.
- This is ideal for large document libraries or lists with thousands of items.
- Schedule Version Cleanup:
- For ongoing version management, automate the process by scheduling PowerShell scripts to run regularly.
- This ensures your SharePoint environment stays optimized without manual effort.
- Test in a Sandbox:
- Before running version cleanup on production sites, test the scripts in a sandbox environment.
- This prevents accidental data loss or unintended consequences.
🔥 Pros and Cons of Deleting Versions
✅ Pros
- Frees up storage space: Reduces the storage footprint by removing unnecessary versions.
- Improves performance: SharePoint performs better with fewer versions to query.
- Enhances data organization: Keeps libraries clean and manageable.
- Lowers costs: Minimizes the need for extra SharePoint Online storage.
❌ Cons
- Potential data loss: Deleting versions without a backup may result in irreversible data loss.
- No built-in recovery: Once versions are deleted, they cannot be recovered unless you have a backup.
- Workflow impact: Deleting versions in active libraries may disrupt workflows dependent on versioning.
🔧 Use Cases for Deleting Versions
- Reducing Storage Costs in SharePoint Online:
- Deleting old versions helps prevent paying for additional storage by keeping usage under the allocated limit.
- Improving List Performance in On-Premises SharePoint:
- Removing outdated versions in large SharePoint lists improves query performance and responsiveness.
- Compliance with Data Retention Policies:
- Ensures you only retain versions required by compliance rules, deleting the rest to avoid legal risks.
🔥 Sample Implementations
🟢 PowerShell Script for SharePoint Online
# Install PnP PowerShell Module (if not installed)
# Install-Module -Name "PnP.PowerShell" -Scope CurrentUser
# Connect to SharePoint Online
$siteUrl = "https://yourtenant.sharepoint.com/sites/yoursite"
Connect-PnPOnline -Url $siteUrl -Interactive
# Set variables
$libraryName = "Documents"
$keepVersions = 5
# Get all items in the library
$items = Get-PnPListItem -List $libraryName -PageSize 500
foreach ($item in $items) {
$file = Get-PnPFile -Url $item.FieldValues["FileRef"] -AsListItem
$versions = $file.Versions
# Delete old versions except the latest X versions
if ($versions.Count -gt $keepVersions) {
for ($i = $keepVersions; $i -lt $versions.Count; $i++) {
$versions[$i].DeleteObject()
Invoke-PnPQuery
Write-Host "Deleted version $($versions[$i].VersionLabel) of $($file.Name)"
}
}
}
Disconnect-PnPOnline
🔵 PowerShell Script for SharePoint On-Premises
# Load SharePoint Snap-in
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
# Variables
$webUrl = "http://yoursite"
$listName = "Documents"
$keepVersions = 5
# Get the web and list
$web = Get-SPWeb $webUrl
$list = $web.Lists[$listName]
# Loop through items and delete old versions
foreach ($item in $list.Items) {
if ($item.Versions.Count -gt $keepVersions) {
for ($i = $keepVersions; $i -lt $item.Versions.Count; $i++) {
$item.Versions[$i].Delete()
}
$item.Update()
Write-Host "Deleted old versions for: $($item.Name)"
}
}
$web.Dispose()
🔗 References
Deleting old versions in SharePoint is an essential practice for maintaining performance, optimizing storage, and managing costs. By following best practices and using PowerShell scripts, you can efficiently clean up your SharePoint environment.
Authentication Automation Backup Batching Compliance Content Type CSS Extensions Flows Google GULP Javascript Limitations Metadata MFA Microsoft Node NodeJs O365 OneDrive Permissions PnP PnPJS Policy Power Automate PowerAutomate PowerShell React ReactJs Rest API Rest Endpoint Send an HTTP Request to SharePoint SharePoint SharePoint List SharePoint Modern SharePoint Online Sharing Is Caring SPFX SPO Sync Tags Teams Termstore Versioning WebParts