Enable Versioning for All Document Libraries in SharePoint

SharePoint versioning feature tracks changes, so that you can View document or item’s version history and audit/recover them if needed. 

How to enable versioning in SharePoint?

The Version feature is configured at 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.
sharepoint enable versioning all document libraries

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 versions created.

Enable Versioning on All Document Libraries of All Sites in SharePoint

Well, activating versioning is quite 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 there is no direct way through UI to enable versioning on all libraries at Site Collection level. Here is where PowerShell scripts comes to help you to enable versioning in all libraries programmatically.

Enable versioning for all document libraries using PowerShell

Add-PSSnapin microsoft.sharepoint.powershell -ErrorAction SilentlyContinue

#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

        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. 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 keep in mind that each version is basically a copy of the document or item. so if you are editing a 10 MB file 10 times, it occupies 100 MB of disk. 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:

Salaudeen Rajack

Salaudeen Rajack is a SharePoint Architect with Two decades of SharePoint Experience. He loves sharing his knowledge and experiences with the SharePoint community, through his real-world articles!

Leave a Reply