All scripts
Microsoft 365 806
Get-SharePointVersionHistorySize
Estimates how much storage is consumed by version history across document libraries, so you know whether trimming version limits is actually worth doing before you change the setting.
Get-SharePointVersionHistorySize.ps1
<#
.SYNOPSIS
Estimates storage consumed by version history per library.
.DESCRIPTION
Walks document libraries in a site and compares total file size
against current version size, giving a rough estimate of how much
space old versions are consuming, so you know whether trimming
version limits is actually worth doing before changing the setting.
.PARAMETER SiteUrl
URL of the site to check.
.EXAMPLE
.\Get-SharePointVersionHistorySize.ps1 -SiteUrl https://contoso.sharepoint.com/sites/finance
.NOTES
Requires PnP.PowerShell.
.AUTHOR
Shehryar Hassan
#>
param(
[Parameter(Mandatory)]
[string]$SiteUrl
)
Connect-PnPOnline -Url $SiteUrl -Interactive
$lists = Get-PnPList | Where-Object { $_.BaseTemplate -eq 101 -and -not $_.Hidden }
$report = foreach ($list in $lists) {
$items = Get-PnPListItem -List $list -PageSize 500
$totalVersionSizeMB = 0
foreach ($item in $items) {
$versions = Get-PnPFileVersion -Url $item.FieldValues.FileRef -ErrorAction SilentlyContinue
$totalVersionSizeMB += (($versions | Measure-Object Size -Sum).Sum / 1MB)
}
[pscustomobject]@{
Library = $list.Title
ItemCount = $items.Count
EstimatedVersionMB = [math]::Round($totalVersionSizeMB, 1)
}
}
$report | Sort-Object EstimatedVersionMB -Descending | Format-Table -AutoSize
Read it before you run it, and test in a safe tenant first.