Configure List Version Limits

By James|04/21/2012|,

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:

  • Crawl all web applications
  • For each web application, crawl all lists
  • For each list, check to see if versioning is enabled
  • If versioning is enabled, check the Major Version Limit
  • If the Major Version Limit is not set to 3, make it 3
  • If the Major Version limit is changed, update all list items and trim excessive versions

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" }
    }
  }
}

 

Copyright 2011 - 2024 The Lazy IT Admin | All Rights Reserved
menu-circlecross-circle linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram