I need to find all the items that has personalization defined on the layout definitions using a Sitecore Powershell Extensions script.
3 Answers
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
-
1Might shave off a few seconds if you narrow it down to sitecore/content. Commented Jul 3, 2018 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}}