SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
May I please get some ideas here? or some snippet – Mike conway Oct 21 '11 at 17:09
up vote 0 down vote accepted


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 ";
share|improve this answer

Your Answer


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.