Last active
August 10, 2016 17:03
-
-
Save hombreDelPez/f11de6ccd3b7721d6e2681b1c33996aa to your computer and use it in GitHub Desktop.
Sitecore PowerShell script to list all orphaned assets
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
<# | |
.SYNOPSIS | |
Lists all media items that are not linked to other items. | |
.NOTES | |
Manuel Fischer | |
#> | |
function HasReference { | |
param( | |
$Item | |
) | |
$linkDb = [Sitecore.Globals]::LinkDatabase | |
$linkDb.GetReferrerCount($Item) -gt 0 | |
} | |
filter IsFile { | |
$templates = Get-ItemTemplate $_ | |
$baseTempls = $templates.BaseTemplates | |
foreach($baseTempl in $baseTempls) { | |
$id = $baseTempl.ID.ToString() | |
if($id -eq "{611933AC-CE0C-4DDC-9683-F830232DB150}") { | |
$_ | |
Return | |
} | |
if($id -eq "{962B53C4-F93B-4DF9-9821-415C867B8903}") { | |
$_ | |
Return | |
} | |
} | |
} | |
function Get-MediaItemWithNoReference { | |
$items = Get-ChildItem -Path "master:\sitecore\media library" -Recurse | ` | |
? { $_.ItemPath -notmatch '/sitecore/media library/System' } | ` | |
? { $_.ItemPath -notmatch '/sitecore/media library/Images/Social' } | ` | |
? { $_.ItemPath -notmatch '/sitecore/media library/nitroNet' } | ` | |
? { $_.ItemPath -notmatch '/sitecore/media library/Default Website' } | ` | |
IsFile | |
foreach($item in $items) { | |
if(!(HasReference($item))) { | |
$item | |
} | |
} | |
} | |
$items = Get-MediaItemWithNoReference | |
if($items.Count -eq 0) { | |
Show-Alert "Es gibt keine unreferenzierte Assets" | |
} else { | |
$props = @{ | |
Title = "Unreferenzierte Assets - Resultate" | |
InfoTitle = "Assets (Bilder, Dokumente, usw...), die nicht (mehr) mit anderen Komponenten verknüpft sind." | |
InfoDescription = "Zeigt alle Assets an, die nicht mehr mit anderen Sitecore-Items verknüpft sind." | |
PageSize = 25 | |
} | |
$items | | |
Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} }, | |
@{Label="Asset type"; Expression={$_.Extension} }, | |
@{Label="Created"; Expression={$_.__Created} }, | |
@{Label="Path"; Expression={$_.ItemPath} } | |
} | |
Close-Window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment