- Get link
- X
- Other Apps
Posted by
Sudheer Kumar Suggu
on
- Get link
- X
- Other Apps
In this blog post, we will explore how to generate a detailed report of content items in Sitecore, including their item page path, rendering name, rendering paths, datasources and datasource path. This report can be invaluable for content audits, troubleshooting, and ensuring consistency across your Sitecore instance. This script can still be customizable as per the need.
We need to run this script in Sitecore powershell and here is the below script.
=======================================================================
# Specify the path to your site's root item
$path = "/sitecore/content/Site/Home"
#Specify the page item language version
$lang = "en"
# Read all the page items including parent and it is child items
$pages = Get-ChildItem -Path "master:$path" -Language $lang -Recurse -WithParent
#Report variable declaration
$reportItems = @()
#Iterates through all the pages
foreach ($page in $pages) {
$contentItemID = $page.ID
$contentItemPath = $page.Paths.FullPath
$renderings = Get-Rendering -Item $page -FinalLayout
foreach($rendering in $renderings)
{
# Checks for whether rendering and datasource is exists or not
$isRendering = ($rendering.ItemID -ne $null -And $rendering.ItemID -ne "")
$isDataSource = ($rendering.DataSource -ne $null -And $rendering.DataSource -ne "")
# Based on the conditions report will be generated
if ($isRendering -And $isDataSource) {
$renderingItem = Get-Item master: -ID $rendering.ItemID
$dataSourceItem = Get-Item master: -ID $rendering.DataSource
$reportItems += ($rendering | Select-Object @{n="Content Path";e={$contentItemPath}}, @{n="Rendering";e={$renderingItem.Name}}, @{n="RenderingPath";e={$renderingItem.Paths.FullPath}}, @{n="DataSource";e={$dataSourceItem.Name}}, @{n="DataSourcePath";e={$dataSourceItem.Paths.FullPath}})
}
elseif ($isRendering) {
$renderingItem = Get-Item master: -ID $rendering.ItemID
$reportItems += ($rendering | Select-Object @{n="Content Path";e={$contentItemPath}}, @{n="Rendering";e={$renderingItem.Name}}, @{n="RenderingPath";e={$renderingItem.Paths.FullPath}},@{n="DataSource";e={"Datasource is empty"}}, @{n="DataSourcePath";e={"Datasource is empty"}})
}
elseif ($isDataSource) {
$dataSourceItem = Get-Item master: -ID $rendering.DataSource
$reportItems += ($rendering | Select-Object @{n="Content Path";e={$contentItemPath}}, @{n="DataSource";e={$dataSourceItem.Name}}, @{n="DataSourcePath";e={$dataSourceItem.Paths.FullPath}},@{n="DataSource";e={"Datasource is empty"}}, @{n="DataSourcePath";e={"Datasource is empty"}})
}
}
}
#Generate the report and show in the Sitecore UI from there we can download the report
$reportItems | Show-ListView
==================================================================================
You can download the script file from my Gist
Here in the above script localize the item path and language to generate this report.
Happy scripting !!!
Comments
Post a Comment
Please do not enter any spam link in the comment box