Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MartinMiles/43e9644a87a9b091952bf518000fddb8 to your computer and use it in GitHub Desktop.
Save MartinMiles/43e9644a87a9b091952bf518000fddb8 to your computer and use it in GitHub Desktop.
Measure-MediaLibrarySize.ps1
# Define the folder path
$folderPath = "master:/sitecore/media library"
# Get all child media items recursively
$mediaItems = Get-ChildItem -Path $folderPath -Recurse -Language * -ErrorAction SilentlyContinue
# Calculate total size (in bytes) using the "Size" field
$totalSizeInBytes = 0
foreach ($item in $mediaItems) {
# Directly read the "Size" field (which should store bytes as an integer)
$sizeValue = [int]$item["Size"]
if ($sizeValue -gt 0) {
$totalSizeInBytes += $sizeValue
}
}
# Convert to megabytes
$totalSizeInMB = [math]::Round($totalSizeInBytes / 1MB, 2)
Write-Host "Total size of $folderPath is $totalSizeInMB MB"
@MartinMiles
Copy link
Author

TODO: verify if does assess SXA variants, and if it does not - add this desired functionality

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment