This post will walk you through limiting the number of major/minor versions in a SharePoint 2010 farm on the Pages and Documents libraries using PowerShell. The script will set the limits, and also purge the older versions.
In SharePoint Server 2010, when versioning is turned on for a library, a full copy of the page or document is created every time that asset is edited and saved. While this can be beneficial for restoring previous versions, it can also consume large amounts of storage over time.
One way to reduce that storage space is to limit the number of major or minor versions of the assets in your SharePoint document libraries. The script below prompts for your site collection URL, and then crawls through each SPWeb updating the number of major/minor versions attached to each library. The script will also delete the older versions.
Param( [Parameter(Mandatory=$True,Position=1)] [string]$SiteURLInput ) #Add Snap-in Microsoft.SharePoint.PowerShell if not already loaded Add-PSSnapin Microsoft.SharePoint.PowerShell -EA 0 function SetVersionLimits ($Url) { $site = Get-SPSite $Url #Step through each web in the site collection, don't include the search sub-site $site | Get-SPWeb -limit all | Where { $_.Url -notlike "*Search"} | ForEach-Object { $webUrl = $_.Url $listNames = @("Pages", "Documents") #Check each Pages and Documents lists. You can add more here if needed. foreach($listName in $listNames) { UpdateLists $webUrl $listName } } $site.Dispose() } function UpdateLists ($webUrl, $listName) { $web = Get-SPWeb $webUrl $list = $web.Lists[$listName] if ($list.EnableVersioning=$true) { $list.MajorVersionLimit = 2 #This is actually 2 plus the current version which gives us 3 total versions $list.MajorWithMinorVersionsLimit = 0 #Keep all minor versions, adjust as necessary $list.Update() Write-Output "Version Limits set for $webUrl list $listName" } foreach ($ListItem in $list.Items) { $ListItem.SystemUpdate() # This update will force the older versions to be deleted } } SetVersionLimits $SiteURLInput