Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 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.

share|improve this answer

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.

share|improve this answer
    
Awsome! Thanks Guys –  Bismarck Apr 26 '12 at 14:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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