Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Delete unused media items older than 30 days in Sitecore
Moves items to the recycle bin which are more than 30 days old and have no references.
Michael West
filter Skip-MissingReference {
$linkDb = [Sitecore.Globals]::LinkDatabase
if($linkDb.GetReferrerCount($_) -eq 0) {
$date = [datetime]::Today.AddDays(-30)
$items = Get-ChildItem -Path "master:\sitecore\media library" -Recurse |
Where-Object { $_.TemplateID -ne [Sitecore.TemplateIDs]::MediaFolder } |
Where-Object { $_.__Owner -ne "sitecore\admin" -and $_.__Updated -lt $date } |
if($items) {
Write-Log "Removing $($items.Length) item(s) older than 30 days."
$items | Remove-Item
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment