0

I'm looking for a way to reset the number of versions to "2" for all lists and libraries that have version control enabled. Is there a PowerShell script or something that can handle this? The idea here is to get a handle on our runaway storage.

Bismarck

2

A little iteration trough all webs and all lists checking if versioning is enabled and if so setting majorversion limit to 2. Then you need to update each item to delete all other versions:

$site = Get-SPSite http://mycoolsitecollection
$webs = $site.AllWebs

foreach ($web in $webs) {
  foreach($list in $web.Lists) {
    if($list.EnableVersioning) { 
      $list.MajorVersionLimit = 2
      $list.Update()
      foreach($item in $list.Items) {
        $item.SystemUpdate($false)
      }
    }
  }
  $web.Dispose()
}

Keep in mind: if you set limit to 2 there will be 3 versions visible when looking at version history (current and last 2).

Also if you have large lists foreach ($item in $list.Items) on items can take a while.

0

You can find a basic idea here in Powershell: http://www.mukalian.com/blog/post/2011/04/10/PowerShell-Script-to-Delete-All-Versions-in-a-Document-Library.aspx

Have a look at http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfileversioncollection_members.aspx for all methods supported. For example you might want to delete just the minor versions.

It might also be a good idea to review the doc library settings and update these to a setting that creates less versions (for example cull all minor versions after two major versions) while you are looping through the document libraries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.