【问题标题】:Delete Duplicate Items In SharePoint List删除 SharePoint 列表中的重复项目
【发布时间】:2014-05-02 22:49:09
【问题描述】:

我有一个包含数千条记录的列表,我需要它们是唯一的。我在网上找到了一个 PowerShell 脚本,如果我只有 1 个唯一列,它就可以工作。但是,我必须按 2 列分组,我不知道如何使它工作。

例如,如果我在 SP 列表中有此数据,则仅当两列重复时才应删除这些项目。

Title     Carrier
1         Carrier1
1         Carrier1     *Remove This One
12        Carrier1
12        Carrier2
100       Carrier1 
100       Carrier1     *Remove This One
100       Carrier2

这是我在网上找到的适用于 1 列但不适用于 2 列的代码示例。

cls
if((Get-PSSnapin | Where {$_.Name -eq "Microsoft.SharePoint.PowerShell"}) -eq $null) {
     Add-PSSnapin Microsoft.SharePoint.PowerShell;
}

$ListName = "DuplicateTest"

$web = Get-SPWeb -identity "http://MyVM/sites/TestSite"
$list = $web.Lists[$ListName]

$AllDuplicates = $list.Items.GetDataTable() | Group-Object Title | where {$_.count -gt 1}
$count = 1
$max = $AllDuplicates.Count
foreach($duplicate in $AllDuplicates) 
{ 
    $duplicate.group | Select-Object -Skip 1 | % {$list.Items.DeleteItemById($_.ID)} 
    Write-Progress -PercentComplete ($count / $max * 100) -Activity "$count duplicates removed" -Status "In Progress" 
    $count++ 
}

【问题讨论】:

  • 想通了,Group-Object Title,Carrier 简单但有效。

标签: sharepoint powershell


【解决方案1】:

实际上,您可能希望将Select-Object-Unique-Property 参数一起使用。

$Deduped$list.Items.GetDataTable() | Select-Object -Property Title, Carrier -Unique;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-16
    • 2017-09-22
    • 1970-01-01
    • 1970-01-01
    • 2011-09-29
    • 2013-08-03
    • 1970-01-01
    相关资源
    最近更新 更多