Last active
April 13, 2020 18:25
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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