2

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

10

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}}
6

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 '18 at 17:32
4

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 agree to our terms of service, privacy policy and cookie policy

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