Enable versioning on all SharePoint Document Libraries in a Site Collection

Enabling versioning on all document libraries in a site collection or disabling versioning is often quite useful.

Write-Host Loading the SharePoint Powershell Snapin

<h1>Load Snapins</h1>

if ((Get-PSSnapin &quot;Microsoft.SharePoint.PowerShell&quot; -ErrorAction SilentlyContinue) -eq $null)
 {
 Add-PSSnapin &quot;Microsoft.SharePoint.PowerShell&quot;
 }

Write-Host &quot;Starting to update lists and Libraries&quot;

$webs = get-spsite http://intranet.domain.com | get-spweb -Limit All
foreach ($web in $webs)
{
Write-Host &quot;Updating Site&quot; $web -foregroundcolor Black -backgroundcolor Yellow
foreach ($list in $web.lists)
{
Write-Host &quot;Looking at list $list&quot;

if ($list.BaseType -eq &quot;DocumentLibrary&quot; -and $list.BaseTemplate -eq &quot;DocumentLibrary&quot;)
{
Write-Host &quot;Updating list $list&quot; -foregroundcolor Black -backgroundcolor Green
$list.EnableVersioning = $true;
$list.EnableMinorVersions = $false;
$list.EnableModeration = $false;
$list.MajorVersionLimit = 0;
$list.ForceCheckout = $false;
$list.Update()
}
}
$web.Dispose()
}
Write-Host &quot;Done updating lists!&quot; -foregroundcolor Black -backgroundcolor Green

Source

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.