Forked from aserogin/Find unused sitecore media Items
Created
January 29, 2023 13:41
-
-
Save sebastiantecsi/ec6cb837a1b8f3b71406695817525ea3 to your computer and use it in GitHub Desktop.
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
# Root path to look 'orphan' items under - update here as needed | |
cd 'master:/sitecore/media library' | |
$counter = 0 | |
$itemsToProcess = Get-ChildItem -Recurse . | Where-Object { $_.TemplateName -ne 'Media Folder' } | |
if ($itemsToProcess -ne $null) { | |
$itemsToProcess | ForEach-Object { | |
$referrers = Get-ItemReferrer -Item $_ | measure | |
if ($referrers.Count -eq 0) { | |
$counter++ | |
Write-Host $_.Paths.FullPath 'no referrers' | |
# commented out for safety reasons :) | |
# $_ | Remove-Item; | |
} | |
} | |
} | |
Write-Host $counter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment