Search This Blog

Monday, December 12, 2011

Delete old versions of List Item via Poweshell SharePoint 2010

Most of the doucments 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://myweburl/
ForEach-Object {ForEach($_.list in $_.Lists){If($_.EnableVersioning -eq $True){if($_.Title -eq "ListName"){Write-host "List:"$_.Title "- List ID"$_.Id;$_.MajorVersionLimit = 1;$_.Update();ForEach($_.item in $_.items){$_.item.URL;$_.update()}}}}}

http://myweburl - Replace with your web URL
ListName - Replace with your list or library name
MajorVersionLimit = 1 - Change 1 to your specific limit

No comments:

Post a Comment