Home Gitesh Portfolio Blog About Me Gallery Contact

Sitecore: Powershell query to remove a rendering from sitecore item.

With this powershell command you will be to remove a rendering from sitecore item.


 

$items = Get-ChildItem -Path "master:/sitecore/content/Home" -Recurse
$rendering = Get-Item master: -ID "{6DDA07A9-18D3-47A0-AB74-DF54956DD5F1}"# Plain HTML
$dataSource = "{F65382DD-AD11-411D-A706-CF05C9C5A332}"# if you want to remove with a specific placeholder.
 
foreach ( $item in $items ) 
{
    $allrenderings = Get-Rendering -Item $item -Rendering $rendering  -DataSource $dataSource
    
    foreach ($allrendering in $allrenderings) 
    {
        write-host "Master Item " $item.Name +  "Rendering name - " + $allrendering.Datasource + "PlcaeholderName - " + $allrendering.Placeholder
        
        Remove-Rendering -Item $item -Rendering $rendering -DataSource $dataSource -Placeholder $allrendering.Placeholder
        
        #remove web item
        $webItem = Get-Item web: -ID $item.ID
        if($webItem)
        {
            write-host "WebItem - " + $webItem.Name
            Remove-Rendering -Item $webItem -Rendering $rendering -DataSource $dataSource -Placeholder $allrendering.Placeholder
        }
    }
}
Posted: 1/06/2022 5:31:30 p.m. by Gitesh Shah | with 0 comments