Sitecore Powershell script to remove renderings of items

Pranay
May 16, 2020  ยท  4479 views

This post would help you to remove the renderings of multiple items in Sitecore using Sitecore Powershell script. This will remove both Shared and Final renderings of the item.

There may be a scenario where you want to remove all renderings of an item in Sitecore. Doing this manually is tedious task, hence a handy Powershell script can make our task easy. Below is the Sitecore Powershell script to remove all the renderings of a single/multiple items in Sitecore.

Is this not the script you are looking for? Then check the complete list of Sitecore Powershell scripts

Sitecore Powershell script to remove renderings of items

$props = @{
   InfoTitle = "Change Template of items"
    PageSize = 10000000
}

$sourcePath = "master:/sitecore/content/Home/Site2"
$items = Get-ChildItem -Path $sourcePath -Recurse
#Uncomment below two lines if you want to include the root item too.
#$rootItem = Get-Item -Path $sourcePath
#$items = $items + $rootItem

function Change-Template {

    # Logic
    foreach($item in $items)
    {
        if ($item.TemplateId -eq "{BAAF9E6D-000F-4C58-9BDF-E0E6F04EF5A9}")
        {
            $item.Editing.BeginEdit();
            $item.Fields["__Renderings"].Value = ""
            $item.Fields["__Final Renderings"] = ""
            $item.Editing.EndEdit();
            Write-Host "Renderings removed for: " $item.ID " 
        }
    }

}

$items = Change-Template
$items | Show-ListView @props -Property ItemPath, ID, @{Label="Language"; Expression={$_."Language"}} 
Close-Window

Remove Sitecore renderings powershell script

AUTHOR

Pranay

A Software Engineer by profession, a part time blogger and an enthusiast programmer. You can find more about me here.


Post a comment




Thank you! You are now subscribed.

Sign up for our newsletter

Subscribe to receive updates on our latest posts.

Thank you! You are now subscribed.