
Today, I am going to share a PowerShell script that can be used to remove the language-specific versions of items located under a specified path mentioned in the script.
In my recent project, I was tasked with a requirement of removing all non-English language versions of items under a particular path. Due to the large number of items, I created this PowerShell script to automate the process and handle everything in one go.
The script is designed to delete non-English language versions (based on my use case) of items within the specified path. After the versions are removed, the processed items are displayed in a list view.
You can easily modify this PowerShell script for other purposes, such as removing versions for a specific language or deleting all language versions entirely.
$props = @{
InfoTitle = "Remove Specific Language Versions"
PageSize = 10000000
}
$sourcePath = "/sitecore/content/Home"
function Remove-Versions {
$items = Get-ChildItem -Path $sourcePath -Recurse
$rootItem = Get-Item -Path $sourcePath
$items = $items + $rootItem
foreach ($item in $items) {
foreach ($version in $item.Versions.GetVersions($true)) {
if ($version.Language -ne "en") {
Remove-ItemVersion $version
Write-Host $version.ID " - "$version.Language "- deleted"
$version;
}
}
}
}
$items = Remove-Versions
$items | Show-ListView @props -Property @{Label = "Path"; Expression = { $_.Paths.Path } }, ID, @{Label = "Language"; Expression = { $_."Language" } }
Close-Window
PowerShell scripts are useful as they are development accelerators that increase productivity and also decrease the time required to deliver a solution.
.png)
.png)
.png)
.png)
References
Sitecore PowerShell - https://doc.sitecorepowershell.com
Sitecore PowerShell GitHub - https://github.com/SitecorePowerShell/Console