I need to find all the items that has personalization defined on the layout definitions using a Sitecore Powershell Extensions script.

up vote 10 down vote accepted

If personalisation is enabled for an item, then there will be a parameter named rules, when we get the rendering using "Get-Rendering". The same can be done for a parent item and run the code for child items which has Rules in its renderings.

I have made a code snippet that will get all the items that has personalization defined

function GetPersonalization($item)    
{
    $count = 0
    $renderingInstance = Get-Rendering -Item $item
    $renderingInstance | ForEach-Object {
        if($_.Rules)
        {
            $count++
        }
    }
    if($count -gt 0)
    {
        return $item
    }
}

$itempath = "/sitecore/content/home/test"
$AllItems = Get-ChildItem -Path $itempath -Recurse
$table = @()
$AllItems | ForEach-Object {
    $table += GetPersonalization -item $_
}

$table | Show-ListView -Property `
   @{ Name="Item Name"; Expression={$_.DisplayName}},
   @{ Name="Item path"; Expression={$_.FullPath}}

You can run fast query and check if __renderings field contains conditions or rule nodes:

$query = "fast:/sitecore//*[@__renderings='%<conditions%' or @#__Final Renderings#='%<conditions%']"
Get-Item -Path "master:" -Query $query
  • 1
    Might shave off a few seconds if you narrow it down to sitecore/content. – Michael West Jul 3 at 17:32

If you combine the answer from @Anton and @Sreekrishnan you get a nice and fast report.

$query = "fast:/sitecore/content//*[@__renderings='%<conditions%' or @#__Final Renderings#='%<conditions%']"
$items = Get-Item -Path "master:" -Query $query
$items | Show-ListView -Property `
   @{ Name="Item Name"; Expression={$_.DisplayName}},
   @{ Name="Item path"; Expression={$_.FullPath}}

enter image description here

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.