I am curious to know if it is possible to export Sitecore master db using PowerShell to a csv or to PowerBI?

I am exploring possibility to get information for a given UI component (e.g. “large hero”) which pages on the Sitecore platform across all tenants host this component?

E.g. Large Hero is hosted only on /membership page

Since you already know the specific component that you want to find references for, you can use the Get-ItemReferrer commandlet.

For example:

$references = Get-ItemReferrer -Path master:\layout\Renderings\Feature\Teasers\MyComponent
$references | Show-ListView 

This will return all reference to the component, including any __Standard Values of templates that you may have the rendering added to.

Internally this uses the Links database so will be much faster than crawling the entire content tree.

  • What if I dont know the location of the item but I have the templateID? – Heng Yon May 29 at 5:06
  • Read the documentation I linked to, you can pass an Id parameter, e.g. Get-ItemReferrer -Id <String> – jammykam May 29 at 12:57

You could install Sitecore PowerShell Extensions module and then use this PowerShell script to get list of renderings used on pages:

write-host 'Running script...'
Set-Location master:\content
$pages = get-item master:\content\home | get-childitem -Recurse
$device = Get-LayoutDevice -Default
$Results = @();
$DataPath = "C:\MySite\ComponentsInUse.csv"

foreach($page in $pages){

    $renderings = Get-Rendering -Item $page -Device $device -FinalLayout

    foreach($rendering in $renderings){

        if($rendering.ItemID -ne $null)
        {
            $renderingItem = Get-Item master: -ID $rendering.ItemID
            if($renderingItem -ne $null)
            {
                $Properties = @{
                    RenderingItemName = $renderingItem.Name
                    RenderingItemID = $renderingItem.ID
                    RenderingItemPath = $renderingItem.Paths.Path
                    UsedOnPage = $page.Name
                    UsedOnPageID = $page.ID
                    UsedOnPagePath = $page.Paths.Path
                }

                $Results += New-Object psobject -Property $Properties
            }
        }

    }
}

$Results | Select-Object RenderingItemName,RenderingItemID,RenderingItemPath,UsedOnPage,UsedOnPageID,UsedOnPagePath | Export-Csv -notypeinformation -Path $DataPath

write-host 'Script ended' 

Script was inspired from this page so please take a look there for further references and examples. I have changed it to suit your needs.

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.