SharePoint Online: Get Site Collection Storage Size – Quota Usage Report using PowerShell

Requirement: Need to generate a report to analyze all SharePoint Online Site collection storage consumption.

How to Get the Storage Metrics of a SharePoint Online Site Collection?

To find the storage details of a site collection, Go to:

  • Click on Settings gear and then select Site Settings.
  • In the “Site Settings” page, under “Site Collection Administration”, click on Storage Metrics.
    get sharepoint online site collection storage metrics

This page gives SharePoint Online site collection storage details along with the breakdown of data usage.

Get Storage Usage of All Sites in SharePoint Online:

Similarly, to check the storage usage of all site collections in SharePoint Online,

  • Login to SharePoint Online Admin Center: https://<tenant>-admin.sharepoint.com
  • Expand Sites >> Active Sites. This page gives you a list of all sites in the tenant along with the storage consumption of each site. You can export this data to CSV as well by clicking on the “Export” link.
    check sharepoint online storage usage

SharePoint Online: Get Site Collection Size using PowerShell

Let’s use the PowerShell script to get the storage size allocated, used, and warning level metrics. This script gets storage info for a single site collection using PowerShell:

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$SiteURL="https://crescent.sharepoint.com/sites/Ops"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –Credential $Cred

#Get the Site collection
$Site = Get-SPOSite $SiteURL
Write-Host "Allocated:"$Site.StorageQuota
Write-Host "Used:"$Site.StorageUsageCurrent
Write-Host "Warning Level:"$Site.StorageQuotaWarningLevel

This PowerShell retrieves SharePoint online site collection quota in MBs.

SharePoint Online: Site Collection Size Report using PowerShell

How to get storage quota in SharePoint Online using PowerShell? Well, This PowerShell script gets storage details such as Total Size allocated, Consumption of all site collections in SharePoint Online.

#Config Parameters
$AdminSiteURL="https://crescent-admin.sharepoint.com"
$ReportOutput="C:\Temp\SPOStorage.csv"

#Get Credentials to connect to SharePoint Admin Center
$Cred = Get-Credential

#Connect to SharePoint Online Admin Center
Connect-SPOService -Url $AdminSiteURL –Credential $Cred

#Get all Site collections
$SiteCollections = Get-SPOSite -Limit All
Write-Host "Total Number of Site collections Found:"$SiteCollections.count -f Yellow

#Array to store Result
$ResultSet = @()

Foreach($Site in $SiteCollections)
{
    Write-Host "Processing Site Collection :"$Site.URL -f Yellow
    #Send the Result to CSV 
    $Result = new-object PSObject
    $Result| add-member -membertype NoteProperty -name "SiteURL" -Value $Site.URL
    $Result | add-member -membertype NoteProperty -name "Allocated" -Value $Site.StorageQuota
    $Result | add-member -membertype NoteProperty -name "Used" -Value $Site.StorageUsageCurrent
    $Result | add-member -membertype NoteProperty -name "Warning Level" -Value  $site.StorageQuotaWarningLevel
    $ResultSet += $Result
}

#Export Result to csv file
$ResultSet |  Export-Csv $ReportOutput -notypeinformation

Write-Host "Site Quota Report Generated Successfully!" -f Green

Here is the CSV file generated by the script to give an overview of the storage usage of all site collections in your tenant:

SharePoint online site collection storage quota report

PowerShell to Get Site Collection Size in SharePoint Online: 

Other than SharePoint Online Management Shell, You can also use CSOM way as an alternate to retrieve storage size metrics of a site collection.

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

$SiteURL="https://crescent.sharepoint.com"

#Get Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
$Site = $Ctx.Site
$Ctx.Load($Site)

#Get Storage Details
$Site.Retrieve("Usage")
$Ctx.ExecuteQuery()
$Site.Usage.Storage

Here is my another post to get OneDrive site collections storage metrics: Get OneDrive Site Collection Storage Quota Size using PowerShell

Get Storage Quota in SharePoint Online with PnP PowerShell

Let’s check SharePoint Online storage using PowerShell and get storage allocated usage, and warning level metrics of storage quota of a SharePoint Online site collection using PnP PowerShell

#Set Variables
$SiteURL = "https://crescent.sharepoint.com"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Credentials (Get-Credential)

#Get the Site collection Storage Metrics
Get-PnPTenantSite -Url $SiteURL | Select @{Label="Allocated (GB)";Expression={$_.StorageMaximumLevel/1MB}}, 
                                         @{Label="Used (MB)";Expression={$_.StorageUsage}}, 
                                         @{Label="Warning Level (GB)";Expression={$_.StorageWarningLevel/1MB}}

If you need to retrieve size of a subsite in SharePoint Online, refer: Get SharePoint Online Subsite Size using PowerShell

Salaudeen Rajack

Information Technology Professional with Two decades of SharePoint Experience.

One thought on “SharePoint Online: Get Site Collection Storage Size – Quota Usage Report using PowerShell

  • May 12, 2021 at 10:12 PM

    another great post, thanks for your work!

    I wonder if there any way to know how much data is allocated for my tenant?(using my licenses plus extras purchased)
    How much data I use across whole tenant (I assume I have to add sizes of all sites, right?)
    and if I’m over the limit, how much then?

    All the posts I can find tell how much data particular SITE uses, but how much MS provides my tenant is something I can’t find. (‘sometimes’ it can be viewed in SP Admin portal but that changed recently for me to something like ‘0.00 MB available of XX.YY TB’)

    thanks in advance!

    Reply

Leave a Reply