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.


$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)



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 = $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)
      Write-Host "Deleted ";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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