/commands/sharepoint-online/get-sposite-storage-usage
Get-SPOSite storage usage: StorageUsageCurrent and StorageQuota for every site
- tool
- SharePoint Online PowerShell
- versions
- Microsoft.Online.SharePoint.PowerShell 16.0.27709.12000
- os
- windows
To see how much storage each SharePoint site uses, connect with Connect-SPOService -Url https://contoso-admin.sharepoint.com and read StorageUsageCurrent and StorageQuota from Get-SPOSite. Both are in megabytes:
Get-SPOSite -Limit All |
Sort-Object StorageUsageCurrent -Descending |
Select-Object Url,
@{n='UsedGB'; e={[math]::Round($_.StorageUsageCurrent / 1024, 2)}},
@{n='QuotaGB'; e={[math]::Round($_.StorageQuota / 1024, 2)}} |
Format-Table -AutoSize-Limit All is needed: without it Get-SPOSite returns at most 200 sites. Run it as a SharePoint Administrator.
The properties
The site object returned by the module has these storage properties; their names and .NET types in version 16.0.27709.12000, read offline:
Import-Module Microsoft.Online.SharePoint.PowerShell -DisableNameChecking
[Microsoft.Online.SharePoint.PowerShell.SPOSite].GetProperties() |
Where-Object Name -in 'Url','StorageUsageCurrent','StorageQuota','StorageQuotaWarningLevel','StorageQuotaType' |
Sort-Object Name | ForEach-Object { '{0,-25} {1}' -f $_.Name, $_.PropertyType.Name }
'Set-SPOSite -StorageQuota type: ' + (Get-Command Set-SPOSite).Parameters['StorageQuota'].ParameterType.NameOutput
StorageQuota Int64 StorageQuotaType String StorageQuotaWarningLevel Int64 StorageUsageCurrent Int64 Url String Set-SPOSite -StorageQuota type: Int64
OneDrive accounts
OneDrive sites are personal sites and are left out by default. Include them with the filter parameter set:
Get-SPOSite -IncludePersonalSite $true -Limit All -Filter "Url -like '-my.sharepoint.com/personal/'" |
Select-Object Owner,Url,StorageUsageCurrent,StorageQuotaChange a site quota
Manual quotas apply only when the tenant's site storage management is set to Manual in the SharePoint admin center (with automatic management, setting a quota returns a generic error). Values are in MB:
# 100 GB quota, warning at 90 GB
Set-SPOSite -Identity https://contoso.sharepoint.com/sites/finance -StorageQuota 102400 -StorageQuotaWarningLevel 92160When to use it
Use this report when the tenant storage pool is filling up, before you set manual quotas, or when a site owner reports that uploads fail because the site is full. Sorting by StorageUsageCurrent shows the few sites that hold most of the data, and comparing it with StorageQuota shows which sites are close to their limit. The same command with -IncludePersonalSite $true covers OneDrive accounts, which often account for a large share of the total.
Requirements
| Requirement | Details |
|---|---|
| Module | Microsoft.Online.SharePoint.PowerShell (SharePoint Online Management Shell), Windows only |
| PowerShell | Windows PowerShell 5.1; in PowerShell 7 import it with -UseWindowsPowerShell |
| Connection | Connect-SPOService -Url https://TENANT-admin.sharepoint.com (the admin URL, not a site URL) |
| Role | SharePoint Administrator or Global Administrator in Microsoft Entra ID |
Export the report
For a spreadsheet, export the same calculated columns to CSV instead of formatting them for the screen:
Get-SPOSite -Limit All |
Select-Object Url, Template, StorageUsageCurrent, StorageQuota, StorageQuotaWarningLevel |
Export-Csv spo-storage.csv -NoTypeInformation -Encoding UTF8-NoTypeInformation keeps Windows PowerShell 5.1 from writing a #TYPE line at the top of the file; see Export-Csv -NoTypeInformation.
Errors you may see
| Message | Cause |
|---|---|
| No connection available. Use Connect-SPOService before running this CmdLet. | Get-SPOSite ran before Connect-SPOService, or the session expired |
| Current site is not a tenant administration site. | Connect-SPOService was given a site URL instead of the -admin URL |
| Cannot convert value ... to type "Microsoft.Online.SharePoint.PowerShell.SpoSitePipeBind" | -Identity received something that is not a site URL |
Fixes: No connection available, Current site is not a tenant administration site, SpoSitePipeBind conversion.
FAQ
Why does Get-SPOSite return only 200 sites?
Without -Limit, Get-SPOSite stops at 200 site collections. Add -Limit All to get every site in the tenant.
Are StorageUsageCurrent and StorageQuota in GB?
No, both are in megabytes. Divide by 1024 for gigabytes, and pass megabytes to Set-SPOSite -StorageQuota and -StorageQuotaWarningLevel.
Can I run this in PowerShell 7?
The SharePoint Online Management Shell is a Windows PowerShell module. Run it in Windows PowerShell 5.1, or in PowerShell 7 on Windows with Import-Module Microsoft.Online.SharePoint.PowerShell -UseWindowsPowerShell.
Sources
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/microsoft.online.sharepoint.powershell/get-sposite
- learn.microsoft.comlearn.microsoft.com/en-us/powershell/module/microsoft.online.sharepoint.powershell/set-sposite
- learn.microsoft.comlearn.microsoft.com/en-us/sharepoint/manage-site-collection-storage-limits