Created
June 20, 2019 15:45
-
-
Save Wesley-Lomax/f742d5577a0ca30d372d81f910c6381d to your computer and use it in GitHub Desktop.
Lists all items in a Sitecore branch with a clone
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
# HasTooManyRenderings determines if the specified item has more than the specified number of renderings. | |
$startItem = Get-Item -Path master:\content\ | |
$resultsPageSize = 30 | |
$props = @{ | |
Title = "Find item clones" | |
Description = "This report will analyse the branch and will tell you which items clones ." | |
Width = 450 | |
Height = 300 | |
OkButtonName = "Proceed" | |
CancelButtonName = "Abort" | |
Parameters = @( | |
@{ Name = "startItem"; Title="Root Item"; Tooltip="Branch you want to analyse."} | |
) | |
} | |
$result = Read-Variable @props | |
if($result -ne "ok") { | |
Close-Window | |
Exit | |
} | |
function HasClone { | |
param( | |
$Item | |
) | |
if(Get-ItemClone -Item $Item){ | |
return $Item; | |
} | |
return ""; | |
} | |
#CMDLET to check whether an item has layout or not. Used to determine whether it's a component or not | |
function Has-Layout{ | |
[CmdletBinding()] | |
param( | |
[Parameter(Mandatory=$true, Position=0)] | |
[Sitecore.Data.Items.Item]$Item | |
) | |
$layout = Get-Layout -Item $Item | |
#Get-Layout returns the layout item. If null means that no presentation is set on the FinalLayout | |
if($layout){ | |
return $Item; | |
} | |
return ""; | |
} | |
# Get-ItemWithTooManyRenderings gets all the items under the start path. | |
function Get-HasClone { | |
$items = Get-ChildItem -Path $startItem.Paths.FullPath -Recurse | Where-Object { (Has-Layout $_) -ne "" } | |
foreach($item in $items) { | |
if(HasClone($item)) { | |
$item | |
} | |
} | |
} | |
# Setup a hashtable to make a more readable script. | |
$props = @{ | |
InfoTitle = "Has Clone" | |
InfoDescription = "Lists all items that clones." | |
PageSize = $resultsPageSize | |
} | |
# Passing a hashtable to a command is called splatting. Call Show-ListView to produce | |
# a table with the results. | |
Get-HasClone | | |
Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} }, | |
@{Label="Updated"; Expression={$_.__Updated} }, | |
@{Label="Updated by"; Expression={$_."__Updated by"} }, | |
@{Label="Created"; Expression={$_.__Created} }, | |
@{Label="Created by"; Expression={$_."__Created by"} }, | |
@{Label="Path"; Expression={$_.ItemPath} } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment