Last active
January 17, 2023 19:36
-
-
Save nehemiahj/81462b5492d4789395ae650691e7c811 to your computer and use it in GitHub Desktop.
Sitecore PowerShell - Get All Page Layout Data
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
#Dialog to select the root folder | |
$dialogParams = @{ | |
Title = "Select the Root Folder" | |
Description = "Select the Root Folder to get default layout data" | |
OkButtonName = "Ok" | |
CancelButtonName = "Close" | |
Width = 450 | |
Height = 450 | |
ShowHints = $true | |
Parameters = @( | |
@{ | |
Name = "sourceItem" | |
Title = "Root Folder" | |
Editor = "droptree" | |
Source = "/sitecore/content" | |
Root="/sitecore/content" | |
Tooltip = "Select the Root Folder to get default layout data (Default: /sitecore/content)" | |
} | |
) | |
} | |
$dialogResult = Read-Variable @dialogParams | |
if($dialogResult -ne "ok") { Exit } | |
if (!$sourceItem) { | |
$sourceItem = Get-Item "master:/sitecore/content" | |
} | |
#Get Default Layout Device | |
$defaultLayout = Get-LayoutDevice "Default" | |
#Generate report with Layout Data | |
Get-ChildItem -Path master: -ID $sourceItem.ID -Recurse ` | |
| Where-Object { (Get-Layout -Item $_ -Device $defaultLayout -ErrorAction SilentlyContinue) -ne $null } | ForEach-Object { | |
$pageRenderings = $null | |
$isFinalLayout = $false | |
if ($_.Fields["__Final Renderings"].Value -ne ""){ | |
$pageRenderings = Get-Rendering -Item $_ -Device $defaultLayout -FinalLayout | |
$isFinalLayout = $true | |
} | |
else { | |
$pageRenderings = Get-Rendering -Item $_ -Device $defaultLayout | |
} | |
if ($pageRenderings) { | |
$groupedComponents = $pageRenderings | Group-Object -Property ItemID ` | |
| Select-Object Count, @{Name="Component";Expression={(Get-Item -Path master -Id $_.Name -ErrorAction SilentlyContinue).Name}} ` | |
| Sort-Object Component | |
#OwnerItemId : {{110D559F-DEA5-42EA-9C1C-8A5DF7E70EF9}} | |
#OwnerItemPath : master:\content\Home | |
#Cachable : | |
#Conditions : | |
#Datasource : | |
#ItemID : Item ID of the rendering. Ex:{885B8314-7D8C-4CBB-8000-01421EA8F406} | |
#MultiVariateTest : | |
#PersonalizationTest : | |
#Parameters : | |
#Placeholder : main | |
#Rules : | |
#UniqueId : {43222D12-08C9-453B-AE96-D406EBB95126} | |
#VaryByData : | |
#VaryByDevice : | |
#VaryByLogin : | |
#VaryByParameters : | |
#VaryByQueryString : | |
#VaryByUser : | |
#ClearOnIndexUpdate : | |
#CacheClearingBehavior : | |
#DynamicProperties : | |
$components = "" | |
foreach ($groupItem in $groupedComponents) { | |
$components += "$($groupItem.Component) - $($groupItem.Count); " | |
} | |
[pscustomobject]@{ | |
"Name"=$_.Name | |
"ID"=$_.ID | |
"Layout"=$components | |
"Has Final Layout"=$isFinalLayout | |
"Path"=$_.Paths.FullPath | |
"Template Name"=$_.TemplateName | |
} | |
} | |
} | Show-ListView | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment