I am working with SP 2010 Sharepoint Lists where the list items is having unique column " Document No" and each items are having "version". Each time the list items are getting updated/New items are created with the same document no and with new version no(incremental) through workflow. I would like to keep one list item for any Document number and the Version no should be latest.
Below is my sample data and how it looks
I am looking for some trick/Suggestion to get this done. Below is the code which will fetch the list items where all the column values are same. But i would like to compare only two columns "Document Number" and " Document version" and delete duplicate values (it doesnt matter if other columns are having different values)
Add-PSSnapin Microsoft.Sharepoint.Powershell
$w = get-spweb "www.contosa.com"
$l = $w.Lists.TryGetList("Test");
$items = $l.Items;
$f = $l.Fields["Check In Comment"];
$listType = $l.GetType().Name;
foreach($item in $items)
{
$itemTitle = $item.Title;
if($listType -eq "SPDocumentLibrary")
{
if($itemTitle -eq ""){$itemTitle = $item["Name"];}
}
if($item.Versions.Count -gt 0){
$vtr = $item.Versions.Count;
Write-Host "$itemTitle, has $vtr versions" -foregroundcolor Green;
}
}