Powershell to delete duplicated in lists with identical names

After a 2010 to 2013 migration I have lots of duplicates in my lists and document libraries.

I found various links to more or less the same code to delete duplicates,

http://geekswithblogs.net/bjackett/archive/2013/03/19/powershell-script-to-remove-sharepoint-2010-or-2013-list-duplicates.aspx

This works well except for lists like blog posts (there are several blogs and all have a list called "Posts")

How do I identify a particular set of blog posts (or other lists with duplicate names) in the line $list = $web.Lists["Posts"]

Add-PSSnapin microsoft.sharepoint.powershell 
$web = Get-SPWeb -Identity "<URL of Site>" 
$list = $web.Lists["Posts"] 

$AllDuplicates = $list.Items.GetDataTable() | Group-Object title | where {$_.count -gt 1} 
$count = 1 
$max = $AllDuplicates.Count 
foreach($duplicate in $AllDuplicates) 

June 30th, 2015 4:17pm

Hi CarolChi,

Each Blog site has only one list called Posts and SharePoint sites do not allow duplicated names for lists, so you will get only one Posts list in the site with the URL set the Get-SPWeb if the site has a list called Posts.

If you want to delete the duplicate items in the post list in a specific Blog site, you can set the URL of the specific Blog site in Get-SPWeb.

Best regards,                        

Sara Fan

Free Windows Admin Tool Kit Click here and download it now
July 1st, 2015 7:56am

What I need is more help with the site syntax.

https://www.mydomain.com/Lists/Technical%20links/AllItems.aspx

How do I get from a URL like the one above to something I can use in get-spweb?

July 9th, 2015 1:21am

Hi CarolChi,

Do you want to get the site URL from the URL in his post automatically?

You could change the url

https://www.mydomain.com/Lists/Technical%20links/AllItems.aspx  to https://www.mydomain.com  manually.

Or you could achieve it by PowerShell command below.

$listURL = "http://yourserver/yoursite/Lists/list1/AllItems.aspx" 

$site = New-Object Microsoft.SharePoint.SPSite($listURL)

$web = $site.OpenWeb()

Write-Output  $web.url

Best regards,

Sara Fan

Free Windows Admin Tool Kit Click here and download it now
July 14th, 2015 2:06am

And when "list1" has a space in it?

technical%20%items ??

July 14th, 2015 2:44am

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics