Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell to find and rename duplicate values in list items
    text
    copied!<p>Is there a way using powershell to find duplicate values in a SharePoint list and rename them as "_1", "_2", "_3", etc.</p> <p>As an example in my test "Products" list I have the following items:</p> <p><img src="https://i.stack.imgur.com/e7hLQ.png" alt="enter image description here"></p> <p>So for the highlighted items above which have duplicated "SAPMaterial" values, is there a way to use powershell to go through the list to find items that have duplicated values and then if duplicate values are found to then update their "SAPMaterial" value to be like:</p> <ul> <li>000000000000227142_1</li> <li>000000000000227142_2</li> </ul> <p>and so on....</p> <p>The reason I want to find out how to do this with powershell is because we have a list with about 300 items and for quite a lot of these items the values in the "SAPMaterial" column have duplicates. This will take forever doing it manually.</p> <p>The powershell I have so far is as follows:</p> <pre><code>#Add-PSSnapin microsoft.sharepoint.powershell $web = Get-SPWeb -Identity "siteURL/" $list = $web.Lists["Products"] $AllDuplicates = $list.Items.GetDataTable() | Group-Object SAPMaterial | where {$_.count -gt 1} $count = 1 $max = $AllDuplicates.Count foreach($duplicate in $AllDuplicates) { $duplicate.group | Select-Object -Skip 1 | % {$list.GetItemById($_.ID).Delete()} Write-Progress -PercentComplete ($count / $max * 100) -Activity "$count duplicates removed" -Status "In Progress" $count++ } </code></pre> <p>Thanks for any suggestions...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload