Globally configure the default number of versions for SharePoint Document Libraries

By default, when turning on versioning in SharePoint, the number of versions is unlimited.  

This is obviously a problem in terms of long term management.  How can the default number of versions be set or propagated?

I have a SQL query that gives me which lists (url and guids) have versioning turned on but I'm looking for the stsadm, webservice or similar command to set the version limit property value.
OCSDTechAsked:
Who is Participating?
 
quihongCommented:
Here is a Powershell script that list out all Document Libraries within a WebApp that has Document Versioning enabled. It list it out to a csv file.

Uncomment the if statement to set the limit.
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint") > $null
# Create the stopwatch
[System.Reflection.Assembly]::LoadWithPartialName("System.Diagnostics.Stopwatch") > $null
$sw = New-Object System.Diagnostics.StopWatch
$sw.Start()

$logFile = "C:\DocumentVersioningEnabled.csv"
$startime = Get-Date
"Script Starting..." + $startime | Out-File -filepath $logFile
"SiteURL`tTitle`tType`tCreatedBy`tEnableVersoning`tEnableMinorVersions`tMajorVersionLimit`tMajorWithMinorVersionsLimit`tCreated`tLastItemModifiedDate`tItemCount" | Out-File -filepath $logFile -append

$WebAppURL =  "http://eportal"
$theSite = New-Object Microsoft.SharePoint.SPSite($webAppURL)
$webApp = $theSite.WebApplication
$allSiteCollections = $webApp.Sites

foreach($site in $allSiteCollections)
{
	foreach($web in $site.AllWebs)
	{
		foreach($list in $web.Lists)
		{
			if($list.EnableVersioning -and $list.Title -ne "Master Page Gallery" -and $list.GetType().Name -eq"SPDocumentLibrary")
			{
				$web.URL + "`t" + $list.Title + "`t" + $list.GetType().Name + "`t" + $list.Author.Name + "`t" + $list.EnableVersioning + "`t" + $list.EnableMinorVersions + "`t" + $list.MajorVersionLimit + "`t" + $list.MajorWithMinorVersionsLimit + "`t" + $list.Created + "`t" + $list.LastItemModifiedDate + "`t" + $list.ItemCount | Out-File -filepath $logFile -append
			
	
				#if($list.MajorVersionLimit -eq 0)
				#{
				#	$list.MajorVersionLimit = 5
				#	$list.update()
				#}
				#if($list.EnableMinorVersions -and $list.MajorWithMinorVersionsLimit -eq 0)
				#{
				#	$list.MajorWithMinorVersionsLimit = 5
				#	$list.update()
				#}			
			}	
		}		
		$web.Dispose()
	}
	$site.Dispose()
}
$Thesite.Dispose()

Open in new window

0
 
liebrandCommented:
There is no way out of the box to solve this problem.
0
 
quihongCommented:
Like all SP administrator, I have this exact same issue.

Our solution (not yet implemented) will be a Powershell Script that uses the SP Object Model.

Here is a tutorial to get you get started - http://www.u2u.info/Blogs/karine/Lists/Posts/Post.aspx?ID=10

I'll try to provide a more specific code sample later today.
0
 
OCSDTechAuthor Commented:
quihong,

Great solution.  I modified the script so that only one library would be changed.  Tested it with Powershell 1.0 and it worked.  

Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.