I am trying to find the duplicate files in my "Test" library in SharePoint, using the below code
[system.reflection.assembly]::LoadWithPartialName("Microsoft.SharePoint")
function Get-DuplicateFiles ($RootSiteUrl)
{
$spsite = new-object Microsoft.SharePoint.SPSite($RootSiteUrl)
$Items = @()
$Duplicates = @()
$duplicateItems = @()
$duplicateshelper = @()
foreach ($SPweb in $spSite.allwebs)
{
Write-Host "Checking " $spWeb.Title " for duplicate documents"
foreach ($list in $spWeb.Lists)
{
if($list.BaseType -eq "DocumentLibrary" -and $list.RootFolder.Url -notlike "_*" -and $list.RootFolder.Url -notlike "SitePages*")
{
foreach($item in $list.Items)
{
$record = New-Object -TypeName System.Object
if($item.File.length -gt 0)
{
$record | Add-Member NoteProperty FileName ($item.file.Name)
$record | Add-Member NoteProperty FullPath ($spWeb.Url + "/" + $item.Url)
$Items += $record
}
}
}
}
$spWeb.Dispose()
$duplicateItems = $Items | Group-Object Filename| Where-Object {$_.Count -gt 1}
foreach($dup in $duplicateItems)
{
foreach($item in $Items | Where-Object {$_.Filename -eq $dup.Name})
{
if ($duplicateshelper -notcontains $item.Fullpath)
{
$duplicateshelper += $item.Fullpath
$found = New-Object -TypeName System.Object
$found | Add-Member NoteProperty Filename ($item.FileName)
$found | Add-Member NoteProperty Fullpath ($item.Fullpath)
$duplicates += $found
}
}
}
}
return $duplicates | Out-GridView
}
Get-DuplicateFiles("http://sp2010/Test")
this giving me result from all the document libraries(Test, SearchCenter, Pages, News) in the site, I want only from "Test" library. Please let me know where to change the code.