Add-Type -AssemblyName "Sitecore.Kernel"
$rootPath = "/sitecore/content/Sites/my site/home/offices"
$templateId = "{xxxxxx-CE5E-42EE-902D-xxxxxxx}"
$renderingId = "{xxxxxxx-7433-4FEB-99F5-xxxxxx}"
# Export path (change as needed)
$timestamp = Get-Date -Format "yyyyMMdd_HHmmss"
$exportPath = "C:\Temp\Offices_Missing_Rendering_$timestamp.csv"
# Get default device (typically 'default')
$device = [Sitecore.Context]::Device
if (-not $device) {
Write-Host "Device context not available. Falling back to master device ID." -ForegroundColor Yellow
$device = Get-Item "/sitecore/layout/Devices/Default"
}
Write-Host "Getting root item at: $rootPath"
$rootItem = Get-Item -Path $rootPath
if (-not $rootItem) {
Write-Host "Root item not found. Exiting." -ForegroundColor Red
return
}
$descendants = Get-ChildItem -Path $rootItem.Paths.FullPath -Recurse | Where-Object {
$_.TemplateID.Guid -eq $templateId
}
Write-Host "Found $($descendants.Count) matching office items."
$itemsWithoutRendering = @()
$index = 1
foreach ($item in $descendants) {
Write-Host "[$index/$($descendants.Count)] Checking item: $($item.Paths.FullPath)"
$finalRenderingsField = $item.Fields["__Final Renderings"]
if ($finalRenderingsField -and $finalRenderingsField.HasValue) {
$layoutXml = [Sitecore.Data.Fields.LayoutField]::GetFieldValue($finalRenderingsField)
if (![string]::IsNullOrWhiteSpace($layoutXml)) {
try {
$layoutDef = [Sitecore.Layouts.LayoutDefinition]::Parse($layoutXml)
if ($layoutDef -ne $null) {
$deviceDef = $layoutDef.GetDevice($device.ID.ToString())
$hasRendering = $false
if ($deviceDef -and $deviceDef.Renderings) {
foreach ($rendering in $deviceDef.Renderings) {
if ($rendering.ItemID -eq $renderingId) {
$hasRendering = $true
break
}
}
}
if (-not $hasRendering) {
Write-Host " -> Rendering NOT found in Final Layout." -ForegroundColor Yellow
$itemsWithoutRendering += [PSCustomObject]@{
Name = $item.Name
Path = $item.Paths.FullPath
ID = $item.ID
}
} else {
Write-Host " -> Rendering found." -ForegroundColor Green
}
} else {
Write-Host " -> LayoutDefinition parsing returned null." -ForegroundColor Yellow
}
}
catch {
Write-Host " -> ERROR parsing layout XML: $_" -ForegroundColor Red
}
} else {
Write-Host " -> Final Renderings field is empty." -ForegroundColor Yellow
$itemsWithoutRendering += [PSCustomObject]@{
Name = $item.Name
Path = $item.Paths.FullPath
ID = $item.ID
}
}
} else {
Write-Host " -> Final Renderings field not found or empty." -ForegroundColor Yellow
$itemsWithoutRendering += [PSCustomObject]@{
Name = $item.Name
Path = $item.Paths.FullPath
ID = $item.ID
}
}
$index++
}
Write-Host "`nTotal items without rendering in Final Layout: $($itemsWithoutRendering.Count)" -ForegroundColor Cyan
# Export to CSV
$itemsWithoutRendering | Export-Csv -Path $exportPath -NoTypeInformation -Encoding UTF8
Write-Host "Export completed: $exportPath" -ForegroundColor Green
I would like to share the things that can provide information or help someone to achieve something. I research, I practice then I share. Please leave your comment if I can do better for you.
Pages without a rendering - Downloadable excel
Subscribe to:
Post Comments (Atom)
Troubleshoot personalization on xm cloud
Here are the troubleshooting steps below that helped personalization to work. We checked the events analytics in the page builder but it was...
-
You might have faced an error while making the container up using the up.ps1 script, and subsequently, when attempting to run docker compos...
-
This is one of the Sitecore templates to create the items but, When can we use this template? and How to create it? Well, the...
-
If you are binding your component with the layout response but feel that if a custom property can come in the layout response and you could ...
No comments:
Post a Comment