PowerShell Script to Delete Child Items


Today I am going to share a PowerShell script that is used to delete all the descendant items of a parent item.

When deleting a Sitecore item with many descendants sometimes the operation times out due to which some of the items do not get deleted.

This PowerShell script will inform you line by line what items are deleted successfully.

$items = Get-ChildItem -Path "/sitecore/content/Home"
foreach ($item in $items)
{
	Write-Host "Deleting Item" $item.Name
	$item | Remove-Item
}


If you want to permanently remove an item without sending those items to recycle bin then you need to add “-Permanently” to the Remove-Item command. Below is the PowerShell script for the same.

$items = Get-ChildItem -Path "/sitecore/content/Home"
foreach ($item in $items)
{
	Write-Host "Deleting Item" $item.Name
	$item | Remove-Item -Permanently
}


References
Chirag Goel

I am a developer, likes to work on different future technologies.

Post a Comment (0)
Previous Post Next Post