Powershell Snippet: Get all large media items in Sitecore

Here’s a quick snippet to the list of media items in Sitecore over 500kb size.

$mediaItemContainer = Get-Item "master:/media library"
$items = $mediaItemContainer.Axes.GetDescendants() | Where-Object { [int]$_.Fields["Size"].Value -gt 500000 } | Initialize-Item

if ($items.Count -eq 0){
    Show-Alert "There are no large media items"
} else {
    $props = @{
    InfoTitle = "Large media items"
    InfoDescription = "Lists all media items larger than 500 kb in size."
    PageSize = 25}
}

$items |
    Show-ListView @props -Property @{Label="Name"; Expression={$_.DisplayName} },
        @{Label="Updated"; Expression={$_.__Updated} },
        @{Label="Updated by"; Expression={$_."__Updated by"} },
        @{Label="Size (kb)"; Expression={[math]::Round($_.Size / 1024)} },
        @{Label="Path"; Expression={$_.ItemPath} }

Sample output

Leave a comment