Last active
August 10, 2016 17:03
-
-
Save hombreDelPez/90a784946201ec4c6b6a732342677e5e to your computer and use it in GitHub Desktop.
Sitecore PowerShell script to list all orphaned renderings
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
<# | |
.SYNOPSIS | |
Lists the components (renderings) which are not or no longer linked to a page. | |
.NOTES | |
Ramon Bruelisauer (original code frame) | |
Manuel Fischer (adjustements und changes for using it with renderings) | |
#> | |
<## | |
# filter HasNoReferrers | |
# --------------------- | |
# Check whether the given item is not linked to any item. | |
#> | |
filter HasNoReferrers { | |
param( | |
[Parameter(Mandatory=$true, ValueFromPipeline=$true)] | |
$Item | |
) | |
Process { | |
$referrers = Get-ItemReferrer -Item $Item | |
If ($referrers -eq $null -or $referrers.Count -eq 0) { | |
$Item | |
} | |
} | |
} | |
<## | |
# filter IsRendering | |
# --------------------- | |
# Check whether the given item is a "Controller rendering" or a "View rendering". | |
#> | |
filter IsRendering { | |
$templateName = $_.TemplateName | |
if ($templateName -eq "Controller rendering") { | |
$_ | |
Return | |
} | |
if ($templateName -eq "View rendering") { | |
$_ | |
Return | |
} | |
} | |
## | |
# Get the content root item from the master database | |
# | |
$database = "master" | |
$contentRootItem = Get-Item -Path "$($database):\content\Master\Home" | |
## | |
# Collect all renderings, which meet the following requirements: | |
# 1. the rendering is using the 'Controller rendering' or 'View rendering' template | |
# 2. the rendering is stored under \layout\Renderings\Master | |
# 3. the rendering does not have any referring items | |
# | |
$renderingsRootItem = Get-Item -Path "$($database):\layout\Renderings\Master" | |
$items = Get-ChildItem -Path $renderingsRootItem.ProviderPath -Recurse | IsRendering | HasNoReferrers | |
## | |
# Create the report output | |
# | |
if($items.Count -eq 0){ | |
Show-Alert "Es wurden keine Renderings gefunden, die nicht (mehr) mit einer Seite/Item verknuepft sind." | |
} else { | |
$props = @{ | |
Title = "Unreferenzierte Renderings - Resultate" | |
InfoTitle = "Renderings, die nicht mehr mit einer Seite/Item verknuepft sind" | |
InfoDescription = "Zeigt die Renderings an, die nicht (mehr) mit einer Seite/Item verknuepft sind" | |
PageSize = 25 | |
} | |
$items | Show-ListView @props -Property @{Label="Rendering Name"; Expression={$_.DisplayName} }, | |
@{Label="Rendering Type"; Expression={$_.TemplateName} }, | |
@{Label="Controller"; Expression={$_.Controller} }, | |
@{Label="Created"; Expression={$_.__Created} }, | |
@{Label="Path"; Expression={$_.ItemPath} } | |
} | |
Close-Window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment