Powershell SharePoint 2010 Clean up SharePoint List Item Versions, BUT keep appended multi-line text entries!

This little gem is for cleaning up stupid versions of list items but keeps versions that contain entries made in appended multi-line text fields:


$web = get-spweb "http://sharepoint/sites/teamabc"
$list = $web.lists["Tracking List"]
$items = $list.items
foreach($item in $items)
{
write-host "-------------------------------------------"$item["Title"]
$versions = $item.versions
for($i=$versions.count-1; $i -ge 0; $i--)
{
if($versions[$i].IsCurrentVersion -eq $false)
{
$itemversion = $versions[$i]
if($itemversion["Tracking Comments"] -or $itemversion["Resolution Comments"])
{
write-host "Not Deleting: " $versions[$i]["Tracking Comments"] "------" $versions[$i]["Resolution Comments"] $i
}
else
{
$count++
write-host "Deleting: " $versions[$i].VersionLabel "------------" $item["Title"] "------------" $count "------------" $i
$item.versions[$i].Delete()
}
}
}
}
$web.dispose()

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

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