Enable Versioning for All Document Libraries in SharePoint
SharePoint versioning feature tracks changes so that you can view a document or item’s version history and audit/restore them if needed. This blog post will show you how to use PowerShell to enable versioning for all document libraries in your SharePoint site.
How to enable versioning in SharePoint?
The Version feature is configured at the list or library level. So, to enable version history:
- Go to your document library >> Click the Library tab on the Ribbon >> Click on Library Settings.
- Under general Settings, click Versioning Settings link.
- From the Versioning Settings page, choose “Create major versions”. Optionally, you can set a limit on number of versions.
This enables SharePoint version history. Once the versioning feature is enabled, you can select a document and click on the “Version History” icon from the Ribbon to view the versions created.
Enable Versioning on All Document Libraries of All Sites in SharePoint
Well, activating versioning is relatively simpler, as shown above! But you may want to enable versioning for all document libraries from all sites in your site collection. You may have a site collection with 100’s of subsites, all with document libraries loaded.
Unfortunately, the web browser UI has no direct way to enable versioning on all libraries at the site collection level. Here is where PowerShell scripts come to help you to enable versioning in all libraries programmatically.
Enable versioning for all document libraries using PowerShell
If you work in a SharePoint, you know that document versioning can be a lifesaver. It allows you to track changes to documents and revert to previous versions if necessary. However, not all document libraries have versioning enabled by default. Here is how to enable versioning for all of your document libraries using PowerShell:
Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue
$webURL="https://demo.crescent.com"
#Get the Web
$web = Get-Spweb $webURL
#Get all lists - Exclude System lists
$ListColl = $web.lists | Where-Object { ($_.hidden -eq $false) -and ($_.IsSiteAssetsLibrary -eq $false) -and ($_.BaseType -eq "DocumentLibrary") }
foreach($list in $ListColl)
{
if ($list.EnableVersioning -eq $false)
{
#Enable Versioning Settings
$list.EnableVersioning = $true
$list.MajorVersionLimit = 5 #No. of versions - versioning best practices
$list.EnableMinorVersions = $true #Applicable only to Libraries
$list.MajorWithMinorVersionsLimit = 5 #No. of Drafts in Lists
$list.Update()
write-host Versioning enabled for: $list.RootFolder.URL
}
}
This script enables versioning programmatically in the entire site.
How to enable versioning by default?
Versioning is disabled by default! There is no automatic versioning in SharePoint, and there is no OOTB way to turn on versioning globally. One trick could be: using List templates – Create a Base list or library, Enable versioning, Save list as template. Any list or library created from this template has versioning turned on by default! You can also try Event Receivers – ListAdded event.
SharePoint Versioning best practices:
It is important to remember that each version is a copy of the document or item. So if you are editing a 10 MB file 10 times, it occupies 100 MB of disk space. (in SharePoint 2016 and later, this is improved! SharePoint just stores the delta to minimize storage space). This could eventually affect the performance of your site. So, It’s a best practice to set versioning limits. Thankfully, SharePoint 2013 shredded storage brings the advantage of storing only the versioning delta.
Related Posts:
- SharePoint versioning clean up – delete old versions with PowerShell
- SharePoint versioning versioning disk space storage report C#Â
- Export SharePoint version history to Excel
- Delete All Document Versions in SharePoint Document Library using PowerShell
- SharePoint versioning report with PowerShell
- SharePoint Versioning Manager – Control Versioning Settings & Clean Up Old Versions
Sorry, this script is functional for SP Server, if I try to apply this number of versioning for SPO it returns an error “SPWeb” is unrecognize Cmlt.
The above script is written for SharePoint On-Premises. For SharePoint Online, refer: SharePoint Online: Enable Versioning on All List and Libraries using PowerShell