Sitecore PowerShell Script to Update renderings cacheable setting to true
Prerequisites: Sitecore PowerShell Extensions
Recently came across this PowerShell script that lists all renderings irrespective of if Cacheable is set to true or false:
https://gist.github.com/michaellwest/b4352327d13447c427cf
In order to just list the renderings where Cacheable is set to true, just added an extra condition like this:
$VerbosePreference = "continue"
$path = "master:/sitecore/layout/renderings"
Write-Log "Get all renderings and determine if caching is enabled."
Get-ChildItem -Path $path -Recurse |
Where-Object { $_.TemplateName -ne "Rendering Folder" -and $_.Cacheable -eq "1"} |
Format-Table -AutoSize -Property Name, ItemPath, ID, @{"Name"="Cacheable";"Expression"={$_.Cacheable -eq "1"}}
Going a step ahead, I wanted to build an Update Script that will automatically set the Cacheable checkbox to true. So, came up with this script:
$VerbosePreference = "continue"
$path = "master:/sitecore/layout/renderings"
Write-Log "Get all renderings and update cacheable to true."
foreach($item in Get-ChildItem -Path $path -Recurse |
Where-Object { $item.TemplateName -ne "Rendering Folder" }) {
$item.Editing.BeginEdit()
$item.Fields["Cacheable"] = "1"
$item.Editing.EndEdit() | Out-Null
}
Write-Log "Update Complete."
Don't forget to add a narrower path to $path variable else all renderings will be set to cacheable true!
Comments
Post a Comment