Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a powershell way to delete duplicate items from document library. there is a column called "OLDGUID" which is same between two files (alone with many other columns). I would like to keep the earlier one (so modified column). Any help will be appreciated.

Thanks

$site = SPSite("http://teams.contoso.com")
$web = $site.rootweb
$list = $web.Lists["Announcements"]
# I may need to run a caml query ...
if($deaditem.count -gt or -e 2)
{
  # compare modified date and keep the earliest one
 (get-date $deaditem) -lt (get-date 2010-01-01)
 $deaditem.Delete()
}

$web.Dispose()
$site.Dispose() 
share|improve this question
    
    
May I please get some ideas here? or some snippet –  Mike conway Oct 21 '11 at 17:09
add comment

1 Answer

up vote 0 down vote accepted

Mike,

Here is the working code.

$webUrl = "http://Biochemistry.Lab.UOF/Sites/Research"
$web = Get-SPWeb $webUrl
$list = $web.Lists["CurrentResearch"]

$caml = "<Where><Contains><FieldRef Name=`"ResearchName`" /><Value Type=`"Text`">DNA PCR Test</Value></Contains></Where>"
$cQuery=new-object -TypeName "Microsoft.SharePoint.SPQuery"
$cQuery.Query = $caml
$myItems=null

$myItems = $list.GetItems($cQuery);
Write-Host ("Items returned = [" + $myItems.Count + "]")

if ($myItems.Count -gt 1)
{
for ($i=1; $i -le $myItems.Count; $i++)     
{
   if($i -ne 0)
   {                
      $myItems[$i].Delete();
      Write-Host "Deleted ";
   }
}
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.