If you want to delete Sitecore items whose name ends with some characters (say, v2),
- Use to delete or recycle an item.
- Accepts items returned by
Get-ItemandGet-ChildItem.
$rootPath = "/sitecore/content/sitename" # Specify the root path where you want to start searching
$itemsToDelete = Get-ChildItem -Path $rootPath -Recurse | Where-Object { $_.Name -like "*v2" }
foreach ($item in $itemsToDelete) {
Remove-Item -Path $item.ItemPath -Force
}
Write-Host "$($itemsToDelete.Count) items with 'v2' at the end of their names were deleted."
Similarly, if you want to delete all items whose name does not end with v2, use following:
$itemsToDelete = Get-ChildItem -Path $rootPath -Recurse | Where-Object { $_.Name -notlike "v2$" }
There are other commands from Sitecore PowerShell that can also be of great use in scenarios like this:
Remove-BaseTemplate
Remove one or more base templates from a template item.
Remove-BaseTemplate -Path "master:/sitecore/content/Feature/Product Page" -Template "/sitecore/templates/Feature/BaseContent"
Remove-ArchiveItem
To archive or restore item, follow this.
To removes items permanently from the specified archive, run the following commands:
$database = Get-Database -Name "master"
$archiveName = "recyclebin"
$archive = Get-Archive -Database $database -Name $archiveName
Get-ArchiveItem -Archive $archive | Remove-ArchiveItem
Remove-ItemVersion
Alias: Remove-ItemLanguage
Removes Language/Version from a single item or a branch of items

Remove-ItemVersion -Path master:\content\home -Language * -MaxRecentVersions 3 -Recurse
It will leave the recent 3 versions and delete the older ones. For more syntax for language or version delete, check Remove-ItemVersion
Leave a comment