Powershell update

ok
03 Mar, 24
Sitecore

# Specify the ID of the rendering you're searching for

$renderingId = "{RENDERING-ID-HERE}"


# Define the root path from where to start the search for content items

$contentRootPath = "master:/sitecore/content"


# Retrieve and search all content items

$contentItems = Get-ChildItem -Path $contentRootPath -Recurse

foreach ($item in $contentItems) {

    # Check both shared and final layouts for the rendering

    foreach ($layoutType in @("", "-FinalLayout")) {

        $renderings = Get-Rendering -Item $item $layoutType | Where-Object { $_.ItemID -eq $renderingId }

        if ($renderings) {

            foreach ($rendering in $renderings) {

                Write-Host "Found rendering in $($layoutType -replace "-","") layout of item: $($item.Paths.Path)"

            }

        }

    }

}


# Retrieve and search all templates' standard values for the rendering

$templates = Get-ChildItem -Path "master:/sitecore/templates" -Recurse | Where-Object { $_.TemplateName -eq "Template" }

foreach ($template in $templates) {

    $standardValues = Get-ChildItem -Path $template.Paths.FullPath | Where-Object { $.Name -eq "_Standard Values" }

    if ($standardValues) {

        foreach ($layoutType in @("", "-FinalLayout")) {

            $renderings = Get-Rendering -Item $standardValues $layoutType | Where-Object { $_.ItemID -eq $renderingId }

            if ($renderings) {

                foreach ($rendering in $renderings) {

                    Write-Host "Found rendering in $($layoutType -replace "-","") layout of standard values for template: $($template.Paths.Path)"

                }

            }

        }

    }

}