Created
September 17, 2020 00:52
-
-
Save danielrolfe/2f8c6c7ed2ebf97ab5dae5324baf9ea0 to your computer and use it in GitHub Desktop.
Removes language versions of Sitecore media library items
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$mediasourceRootPath = "master:/sitecore/media library" | |
$isDryRun = $false | |
Write-Host "Cleaning up Media Library language versions for all items under this path: " $location | |
$time = Measure-Command { | |
New-UsingBlock (New-Object Sitecore.Data.BulkUpdateContext) { | |
New-UsingBlock (New-Object Sitecore.SecurityModel.SecurityDisabler) { | |
New-UsingBlock (New-Object Sitecore.Data.DatabaseCacheDisabler) { | |
New-UsingBlock (New-Object Sitecore.Data.Events.EventDisabler) { | |
Get-ChildItem $mediasourceRootPath -Language * -Recurse | ForEach-Object { | |
$isSystem = $_.FullPath -match "/sitecore/media library/system" | |
$isSkipList = $_.FullPath -match "/sitecore/media library/Images/PreSales" | |
$isPrunable = $_.Extension -match "pdf" -OR $_.Extension -match "jpg" -OR $_.Extension -match "jpeg" -OR $_.Extension -match "svg" -OR $_.Extension -match "png" -OR $_.Extension -match "webp" -OR $_.Extension -match "mov" -OR $_.Extension -match "swf" -OR $_.Extension -match "gif" -OR $_.Extension -match "ogg" | |
$isFolder = $_.TemplateName -eq "Media folder" | |
if ($isSystem -OR $isSkipList -OR -NOT $isPrunable) { | |
if(!$isFolder){ | |
Write-Host "Skipping library item: " $_.FullPath -foregroundcolor "yellow" | |
Write-Log "Skipping library item: " $_.FullPath | |
} | |
} | |
else { | |
if (!$isDryRun) { | |
Write-Host "Removed language versions: " $_.FullPath -foregroundcolor "green" | |
Write-Log " remove language versions: " $_.FullPath | |
Remove-ItemLanguage $_ -Language "en-GB" | |
Remove-ItemLanguage $_ -Language "en-AU" | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
Write-Host "Finished removing language versions for Media Library " |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment