Updating renderings properties using Sitecore Powershell Extensions

Have you ever needed to update a rendering property on several items in your Sitecore content tree and didn’t want to go through the process manually? Well recently I had, and if I had to do it manually one by one, it take a lot of time as I had several items I needed to perform such task. Whenever you face a situation like this, you might want to consider using the powershell extensions module.

By the way If you are working with Sitecore and you are not familiar with the powershell extensions module I highly recommend you start using it. It can save you a lot of time. You can download the module at the marketplace.

So in this scenario I wanted to update a rendering on all items of a specific template and set the caching “Vary By Data” property to checked on all of them.

Here is how you can easily do that by running this script:

$items = Get-ChildItem -Recurse | Where-Object {$_.TemplateID -match “{79A0F7AB-17C8-422C-B927-82A1EC666ABC}”} | ForEach-Object {

$renderingInstance = Get-Rendering -Item $_ -Rendering $rendering
$renderingInstance.VaryByData = 1
Set-Rendering -Item $_ -Instance $renderingInstance



So what this script is doing is pretty straight forward but in any case here is the explanation on what it does.

It is getting all descendants of the Sitecore Context, in this case sitecore\content\home and it is filtering for all descendants that have the TemplateID guid as “{79A0F7AB-17C8-422C-B927-82A1EC666ABC}”.
Next it will loop on the results and set to the renderingInstance variable the rendering. If it’s not null it sets the VaryByData property to 1(checked) and execute the Set-Rendering command.
At this point all renderings on the items will have been set to “Vary By Data” as checked as shown bellow:


One thought on “Updating renderings properties using Sitecore Powershell Extensions

  1. Would have made more sense to set the cache settings on each individual rendering under /Sitecore/Layout/Renderings rather than on the individual instance in the items… generally I’ll only do this as an exception and setting it on the Rendering itself means it’s easy to change in the future rather than having to run an SPE script over all the items again.

    Nice script that the general gist of which will be useful for other things.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s