Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to find all components / renderings added on an item in Sitetree

With this powershell command you will be to find all components / renderings added on an item in Sitetree.

 

<#
  This script will Find all components / renderings added on an item in Sitetree.
  Goes through all child items and finds the renderings for that item
#>

$allRendering = Get-ChildItem -Path "master:\layout\Renderings" -Recurse | 
Where-Object { $_.TemplateName -like "*rendering*" } | 
Select-Object Name, ID, TemplateName | 
Sort-Object -Property Name 
$rootPath = 'master:/sitecore/content/IR/Home/Home/about-this-site'
$itemsToProcess = Get-ChildItem -Path $rootPath -Recurse 
$list = @()
foreach ($item in $itemsToProcess) {
    $itemRenderings = Get-Rendering -Item $item -FinalLayout #| Where-Object { $_.Cachable -ne "1" }
    foreach ($itemRendering in $itemRenderings) {
    
        $renderingItem = $allRendering | Where-Object { $_.ID -eq $itemRendering.ItemID }
        if ($renderingItem -ne $null) {
            $itemRendering = [PSCustomObject]@{
                ItemPath                 = $item.Paths.FullPath
                RenderingName            = $renderingItem.Name
                RenderingId              = $renderingItem.ID
            }            
             
            $list += $itemRendering            
        }    
    } 
}
$reportProps = @{
	Property = @(				
		@{Name="ItemPath"; Expression={$_.ItemPath}},
		@{Name="RenderingName"; Expression={$_.RenderingName}},
        @{Name="RenderingId"; Expression={$_.RenderingId}}
	)
	Title = "Find all components / renderings added on an item in Sitetree"
	InfoTitle = "Goes through all child items and finds the renderings for that item"
	InfoDescription = "Find all renderings."
}
$list | Show-ListView @reportProps

Close-Window

Posted: 10/12/2022 1:54:41 a.m. by Gitesh Shah | with 0 comments