Find all duplicate items from SharePoint list by using PowerShell.
ListItemsDuplicate.ps1
Param($WebUrl,$ListName);
Add-PSSnapin Microsoft.SharePoint.PowerShell
function Main($WebUrl,$ListName)
{
Write-Host -Fore Green "Starting..."
Write-Host -Fore Green "Web Url :" $WebUrl
Write-Host -Fore Green "List Title :" $ListName
$web = Get-SPWeb -Identity $WebUrl
$list = $web.Lists[$ListName]
$AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1}
if($AllDuplicates.Count -gt 0)
{
Write-Host -Fore Green "Duplicate items count: " $AllDuplicates.Count
foreach($duplicate in $AllDuplicates)
{
$duplicate.Group | Format-Table @{Label="Title";Expression={$_["Title"]}},@{Label="Item Id";Expression={$_["ID"]}} -Autosize
}
}
else
{
Write-Host -Fore Green "Duplicate items count: 0"
}
Write-Host -Fore Green "End..."
}
Start-Transcript
Main $WebUrl $ListName
Stop-Transcript
ListItemsDuplicate.bat
echo off
cd %SystemRoot%\system32\WindowsPowerShell\v1.0
powershell {Set-ExecutionPolicy Unrestricted}
cd /d %~dp0
SET WebUrl="http://servernme:7576/productcenter"
SET ListName="Marine ADR"
powershell.exe -command .\ListItemsDuplicate.ps1 '%WebUrl%' '%ListName%'
powershell {Set-ExecutionPolicy Restricted}
pause
ListItemsDuplicate.ps1
Param($WebUrl,$ListName);
Add-PSSnapin Microsoft.SharePoint.PowerShell
function Main($WebUrl,$ListName)
{
Write-Host -Fore Green "Starting..."
Write-Host -Fore Green "Web Url :" $WebUrl
Write-Host -Fore Green "List Title :" $ListName
$web = Get-SPWeb -Identity $WebUrl
$list = $web.Lists[$ListName]
$AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1}
if($AllDuplicates.Count -gt 0)
{
Write-Host -Fore Green "Duplicate items count: " $AllDuplicates.Count
foreach($duplicate in $AllDuplicates)
{
$duplicate.Group | Format-Table @{Label="Title";Expression={$_["Title"]}},@{Label="Item Id";Expression={$_["ID"]}} -Autosize
}
}
else
{
Write-Host -Fore Green "Duplicate items count: 0"
}
Write-Host -Fore Green "End..."
}
Start-Transcript
Main $WebUrl $ListName
Stop-Transcript
ListItemsDuplicate.bat
echo off
cd %SystemRoot%\system32\WindowsPowerShell\v1.0
powershell {Set-ExecutionPolicy Unrestricted}
cd /d %~dp0
SET WebUrl="http://servernme:7576/productcenter"
SET ListName="Marine ADR"
powershell.exe -command .\ListItemsDuplicate.ps1 '%WebUrl%' '%ListName%'
powershell {Set-ExecutionPolicy Restricted}
pause
No comments:
Post a Comment