PowerShell EnableVersioning_MajorVersionLimit_AllDocLibs

My TFS Admin colleague needed a script to go through all of the libraries in her project sites and turn on versioning with a 5 version limit.  We didn’t want to turn it on for all libraries, so that’s where the additional “notlike”s came in.

#Get site collection
  $site = Get-SPSite -Identity http://WEBAPP/sites/TFSSITECOLLECTION 
#Go through each site in the site collection
$site | Get-SPWeb -limit all | ForEach-Object { 
 write-host "Checking site:"$_.Title 
#Go through each document library in the site
 $_.GetListsOfType("DocumentLibrary") | where { $_.BaseTemplate -eq "DocumentLibrary" -and $_.Title - notlike "*Site*" -and $_.Title -notlike "*Templates*" -and $_.Title -notlike "*Style*"} | ForEach-Object {
 write-host "Library:"$_.Title 
#Make the list changes
  #$_.EnableVersioning = $true
  #$_.MajorVersionLimit = 5
#Update the list
  $_.Update()  
}  
}  
#Dispose of the site object
  $site.Dispose()
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: