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
Output
Here is a sample output:
Url | StorageUsage | StorageMaximumLevel | Usage in % |
https://mytenant.sharepoint.com/ | 1235 | 10240 | 12.06 |
https://mytenant.sharepoint.com/portals/hub | 1 | 10240 | 0.01 |
https://mytenant.sharepoint.com/search | 27 | 10240 | 0.26 |
https://mytenant.sharepoint.com/sites/americas | 4323 | 10240 | 42.22 |
https://mytenant.sharepoint.com/sites/asia | 149 | 10240 | 1.46 |
https://mytenant.sharepoint.com/sites/emea | 109 | 10240 | 1.06 |
Note: StorageUsage and StorageMaximumLevel are shown in MB
new blog post: Office 365 Advent Calendar – 02 Retrieving SharePoint Online Site Collection Sizes https://t.co/tIh0qCxutf #office365
Office 365 Advent Calendar – 02 Retrieving SharePoint Online Site Collection Sizes https://t.co/8frNBssf7P #Office365
Office 365 Advent Calendar – 02 Retrieving SharePoint Online Site Collection Sizes https://t.co/BgMoNNmvNf #office365adventcalendar
RT @modery: Office 365 Advent Calendar – 02 Retrieving SharePoint Online Site Collection Sizes https://t.co/BgMoNNmvNf #office365adventcale…
This works perfectly, but returns 300 site collections only. Any idea how to fetch ALL site collections?
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
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
Hi Rene, any updates with the 300 site collection limit?
JanK, Mark, the issue has been resolved.
Check, for ‘normal’ site collections this works perfectly! However, seems when adding the -IncludeOneDriveSites parameter, only a subset of the personal sites is returned.