office-365-advent-calendar

Scenario

You want to get an overview of the storage usage of all site collections in your tenant, similar to what you can see in the “SharePoint Administration” section in Office 365. But as you may have hundreds of site collections, or as you want to pass on that information to someone else, you want to extract this information into a spreadsheet

Code

$cred = Get-Credential
Connect-PnPOnline -Url "https://mytenant-admin.sharepoint.com" -Credentials $cred
$sites = Get-PnPTenantSite -Detailed | select Url, StorageUsage, StorageMaximumLevel, @{label="Usage in %";Expression={[math]::Round($_.StorageUsage*100/$_.StorageMaximumLevel,2)}}
$sites | Export-Csv C:\SiteStorage.csv

Code on GitHub

Output

Here is a sample output:

UrlStorageUsageStorageMaximumLevelUsage in %
https://mytenant.sharepoint.com/12351024012.06
https://mytenant.sharepoint.com/portals/hub1102400.01
https://mytenant.sharepoint.com/search27102400.26
https://mytenant.sharepoint.com/sites/americas43231024042.22
https://mytenant.sharepoint.com/sites/asia149102401.46
https://mytenant.sharepoint.com/sites/emea109102401.06

Note: StorageUsage and StorageMaximumLevel are shown in MB

10 thoughts on “Office 365 Advent Calendar – 02 Retrieving SharePoint Online Site Collection Sizes”

    1. Hi Jan, I’m testing it. Had a quick check if there are any limits in the code, but it should return all. Interestingly, all my sites are currently reported as 0 bytes large, so maybe there are a few other issues on the backend

    2. Good catch! The CSOM cmdlets actually need to be improved, as the underlying code only retrieves 300 site collections at one time. I’ll open an issue and will see if I can code the fix myself. Will post an update here once done

    1. Check, for ‘normal’ site collections this works perfectly! However, seems when adding the -IncludeOneDriveSites parameter, only a subset of the personal sites is returned.

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.