Tuesday, August 14, 2012

How To Purge Old Versions of Documents Keeping Only Major Version

Most of the documents were having lots of versions so the need was to remove all the existing versions except the latest version.

You can change this script to complete all the operation at one time means for all the libraries and lists under a web or all the site collections or all the web applications with in a farm.

The following script will remove all the existing versions of the documents except latest one.
PowerShell Command Prompt:

get-spWeb http://teamsite/
ForEach-Object {ForEach($_.list in $_.Lists){If($_.EnableVersioning -eq $True){if($_.Title -eq "Shared Documents"){Write-host "List:"$_.Title "- List ID"$_.Id;$_.MajorVersionLimit = 1;$_.Update();ForEach($_.item in $_.items){$_.item.URL;$_.update()}}}}}


Note:
http://Teamsite - Replace with your web name
Shared Documents - Replace with your list or library name
MajorVersionLimit = 1 - Change 1 to your specific limit

No comments:

Post a Comment