Get-TenantStorage
This PnP PowerShell script connects to the SharePoint admin centre, retrieves storage data for every site collection in the tenant, and exports a dated CSV report. Each site is assessed for storage usage percentage and days since last activity, with a Flag column identifying sites that are approaching their quota or have been inactive for more than six months.
Purpose
Tenant-wide storage reporting is the starting point for any storage governance exercise. This script gives you an actionable snapshot by:
- Querying all SharePoint site collections (OneDrive excluded by default)
- Calculating storage used as a percentage of each site's quota
- Calculating days since last content modification for each site
- Flagging sites over 80% storage usage as
High Usage - Flagging sites with no activity in over 180 days as
Inactive - Exporting a dated CSV so reports can be compared over time
Prerequisites
- PnP PowerShell module installed
- SharePoint Administrator or Global Administrator permissions
- A registered Entra ID app with SharePoint admin-scoped permissions and a Client ID
Parameters to update
- Url — your SharePoint admin centre URL in the format
https://tenantName-admin.sharepoint.com - ClientId — your registered Entra ID app Client ID
- Flag thresholds — adjust
80(high usage %) and180(inactive days) to match your governance policy
Output
A CSV file named StorageReport_YYYYMMDD.csv exported to the directory from which the script is run. Columns: Url, StorageMB, QuotaMB, PercentUsed, DaysSinceActivity, Owner, Flag.
PowerShell Script
$clientId = ""
Connect-PnPOnline -Url "https://tenantName-admin.sharepoint.com" -ClientId $clientId -Interactive
$sites = Get-PnPTenantSite -IncludeOneDriveSites:$false |
Select-Object Url, StorageUsageCurrent, StorageQuota, LastContentModifiedDate, Owner
$report = $sites | ForEach-Object {
$percentUsed = if ($_.StorageQuota -gt 0) {
[math]::Round(($_.StorageUsageCurrent / $_.StorageQuota) * 100, 1)
} else { 0 }
$daysSinceActivity = if ($_.LastContentModifiedDate) {
(New-TimeSpan -Start $_.LastContentModifiedDate -End (Get-Date)).Days
} else { 999 }
[PSCustomObject]@{
Url = $_.Url
StorageMB = $_.StorageUsageCurrent
QuotaMB = $_.StorageQuota
PercentUsed = $percentUsed
DaysSinceActivity = $daysSinceActivity
Owner = $_.Owner
Flag = if ($percentUsed -gt 80) { "High Usage" }
elseif ($daysSinceActivity -gt 180) { "Inactive" }
else { "" }
}
}
$report | Sort-Object PercentUsed -Descending |
Export-Csv -Path "StorageReport_$(Get-Date -Format 'yyyyMMdd').csv" -NoTypeInformation
Write-Host "Report saved. Sites flagged: $(($report | Where-Object { $_.Flag -ne '' }).Count)"
Usage Notes
- The script excludes OneDrive for Business accounts (
-IncludeOneDriveSites:$false). Remove this flag if you want to include OneDrive in the report StorageUsageCurrentandStorageQuotaare in MB. The script reports them as-is; convert to GB by dividing by 1024 if preferred- The 25 TB figure that often appears in
StorageQuotais the SharePoint platform maximum, not a meaningful per-site quota — sites showing this value have no explicit quota set - Run this script monthly or quarterly and compare the dated CSV exports to track consumption trends over time
- Sites flagged as
Inactiveare candidates for archiving via Microsoft 365 Archive — see the related post below - Sites flagged as
High Usageare candidates for version trimming, archiving, or explicit quota review - On very large tenants,
Get-PnPTenantSitemay take several minutes to complete
Related
- Get-VersionReport — report version counts per file in a specific library once high-consumption sites are identified
- Invoke-VersionTrim — delete versions beyond a threshold in a library after reviewing with Get-VersionReport
- Get Preservation Library — check for hidden compliance storage on sites that show unexpectedly high consumption
- Storage Governance in Microsoft 365 — The Bigger Picture — governance framework and how to use this report as part of a recurring review cycle