How to Enable Versioning in all document libraries in a SharePoint site 2013 Using Powershell

In SharePoint 2010 & 2013, all types of sharepoint list support versions. Versions enable you to store and record or restore the list item from previous versions. SharePoint versioning is disabled by default. You need to have Design Permissions to enable the versioning in SharePoint libraries.

Enabling Versioning through UI is easy and straightforward, if the no of document libary in a site is very less. If you have document library is more than ten in number, Powershell comes for our rescue. Below are the list of  powershell commands to enable versioning  in all document libraries in a SharePoint Site.

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$site = Get-SPSite “http://mysite/site1
foreach($web in $site.AllWebs) {
Write-Host “Inspecting ” $web.Title
foreach ($list in $web.Lists) {
if($list.BaseType -eq “DocumentLibrary”) {
Write-Host “Versioning enabled: ” $list.EnableVersioning
Write-Host “Major Versions: ” $list.MajorVersionLimit
Write-Host “Minor Versions: ” $list.MajorWithMinorVersionsLimit
$list.EnableVersioning = $true
$list.EnableMinorVersions = $true
$list.MajorVersionLimit = 4
$list.MajorWithMinorVersionsLimit = 5
$list.Update()
Write-Host $list.Title ” document library version is enabled successfully”
}
}
}

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published.