Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to find the cache settings for all cached components/renderings

With this powershell query you will be able to find the cache settings for all cached components/renderings.




Import-Function -Name ConvertTo-Xlsx

$allRendering = Get-ChildItem -Path "master:\layout\Renderings" -Recurse | 
    Where-Object { $_.TemplateName -like "*rendering*" -And  $_.Cacheable -eq "1"} | 
    Select-Object Name, ID, TemplateName,  Cacheable | 
    Sort-Object -Property Name 
$rootPath = 'master:/sitecore/content/IR/Home/Home'
$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){
    if($itemRendering.Cachable -ne "1")
      {     
          $renderingItem = $allRendering | Where-Object { $_.ID -eq $itemRendering.ItemID }
              if($renderingItem -ne $null)
              {
                        $itemRendering = [PSCustomObject]@{
                            ItemName     = $item.Name
                            ItemID = $item.ID
                            ItemPath    = $item.Paths.FullPath
                            RenderingName = $renderingItem.Name
                            RenderingId = $renderingItem.ID
                            CacheableOnItem = $itemRendering.Cachable
                            CacheableOnRenderingItem = $renderingItem.Cacheable
                }
                if($itemRendering.CacheableOnRenderingItem -ne "1")
                {
                        $list += $itemRendering
                }
          }
      }
  } 
}
[byte[]]$outobject =  $list | ConvertTo-Xlsx 
Out-Download -Name "report_itemListWithRenderings.xlsx" -InputObject $outobject

Posted: 7/04/2022 5:19:21 p.m. by Gitesh Shah | with 0 comments