Created
December 22, 2024 20:56
-
-
Save MartinMiles/43e9644a87a9b091952bf518000fddb8 to your computer and use it in GitHub Desktop.
Measure-MediaLibrarySize.ps1
This file contains hidden or 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
# 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TODO: verify if does assess SXA variants, and if it does not - add this desired functionality