Powershell script to enable version on all document

Powershell script to enable version on all document libraries(other than catalogs and hidden libraries):

Add-PSSnapin Microsoft.SharePoint.PowerShell -erroraction SilentlyContinue
$siteURL = "<<your site URL>>"
$site = Get-SPSite($siteURL)
foreach($web in $site.AllWebs) {
Write-Host "Inspecting " $web.Title
foreach ($list in $web.Lists) {
if(($list.BaseType -eq "DocumentLibrary") -and ($list.IsCatalog -eq $false))
{
If (($list.EnableVersioning -eq $false) -and ($list.hidden -eq $false))
{ 

If (($list.Title -ne "Style Library") -and ($list.Title -ne "Form Templates"))
{
Write-Host "Versioning enabled: " $list.EnableVersioning
$host.UI.WriteLine()
Write-Host "Major Versions: " $list.MajorVersionLimit
$host.UI.WriteLine()
$list.EnableVersioning = $true
$list.MajorVersionLimit = <<your value>>
$list.Update()
Write-Host $list.Title " is updated with MajorVersionLimit"
}
}
}
}
}
Ebook Download
View all
Learn
View all