سؤال

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() 
هل كانت مفيدة؟

المحلول

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 ";
   }
}
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى sharepoint.stackexchange
scroll top