Skip to content

Instantly share code, notes, and snippets.

@michaellwest
Last active April 13, 2020 18:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michaellwest/587f26083ad028bd9d21f05a29b792f4 to your computer and use it in GitHub Desktop.
Save michaellwest/587f26083ad028bd9d21f05a29b792f4 to your computer and use it in GitHub Desktop.
Find items with a duplicate item name at the same level using Sitecore PowerShell Extensions.
Import-Function -Name Invoke-SqlCommand
$connection = [Sitecore.Configuration.Settings]::GetConnectionString("master")
$query = @"
SELECT
a.[ID],
a.[Name],
a.[ParentID]
FROM [dbo].[Items] a
JOIN (
SELECT
[Name],
[ParentID]
FROM [dbo].[Items]
GROUP BY [Name], [ParentID]
HAVING COUNT(*) > 1
) b
ON a.[Name] = b.[Name]
AND a.[ParentID] = b.[ParentID]
"@
$itemIds = Invoke-SqlCommand -Connection $connection -Query $query -Parameters $parameters | Select-Object -ExpandProperty "ID"
$reportItems = [System.Collections.ArrayList]@()
foreach($itemId in $itemIds) {
if(!$itemId) { continue }
$selectedItem = Get-Item -Path "master:" -ID ([Sitecore.Data.ID]::Parse($itemId))
if($selectedItem) {
$reportItems.Add($selectedItem) > $null
}
}
$reportItems | Show-ListView -Property Name, ItemPath, @{"Name"="Referrer Count"; Expression={Get-ItemReferrer -Id $_.ID | Measure-Object | Select-Object -Expand Count}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment