Versioning is a great SharePoint feature that allows for life's little mistakes to be forgiven. However, if not configured with care, versioned documents can quickly consume significant amounts of space in your content databases. If you have many people that can configure document library properties, this can become a major issue as each person may have their own idea about appropriate versioning settings.
The following script will perform the following actions against a SharePoint farm:
I wrote this script to help combat a single ballooning site collection content database. After running the script, said content database was reduced by 20 GB. Enjoy!
# Version: 1.0 29FEB12 # Author: James Sanders # Purpose: Enumerate all portal lists to determine which have versioning enabled. # For lists that have versioning enabled, set Major Version Limit to 3 and clean up items # Load SharePoint PowerShell extensions "- Loading SharePoint extensions" Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue "- Enumerating web sites" $webs = Get-SPWebApplication | Get-SPSite -Limit All | Get-SPWeb -Limit All "- Enumerating versioned lists" ForEach ($web in $webs) { ForEach ($list in $web.Lists) { If ($list.EnableVersioning -eq $TRUE) { "`nChecking list: $($web.Url)/$list" If ($list.MajorVersionLimit -ne 3) { $list.MajorVersionLimit = 3 $list.Update() ForEach ($item in $list.Items) { "Versioning $($item.URL)" $item.SystemUpdate() } } Else { "Major version limit already configured correctly" } } } }