How to Read SharePoint Storage Capacity with Graph
By Anatoly Mironov
Do you want to monitor the storage capacity of your SharePoint Online Environment in an automated way? In this blog post, I will show you how to use Graph to read the storage capacity programmatically and avoid running out of storage space.
Hey SharePoint Admin, have you also gazed at this storage chart in Active Sites section and scratched your head? Sure, it is good, but you cannot use it for automated monitoring. Now you can! With Graph, I’ll show you in a moment, but first, let me introduce the diagnostic tool. This humble tool might shed light on what to look after in the Graph calls.
(If you’re impatient, just scroll to the end of the blog)
Storage Diagnostic Tool
A while ago I discovered that there is a diagnostic tool for Storage in the M365 Admin Center. There is a direct link to the diagnostic tool that you can find on this MS Learn page:
But you can also just head to the help center, type “SharePoint Storage” and this diagnostic tool will pop up for you. Select your tenant (don’t type it, just select it in the dropdown menu):
The screenshots are from my Developer Programme Tenant, there are more lines in a production tenant.
In my previous blog post I presented how it was calculated behind the scenes.
The news (this blog post) is that you can calculate it too, just by firing a couple of Graph Calls, more details below.
The storage capacity in SharePoint Online is calculated based on the number and type of licenses and add-ons that your organization has purchased. You can find the formula and the list of eligible plans on the SharePoint Limits page.
Imagine an organization that has E3 and E5 licenses, some Visio licenses and some additional storage. The products that make up sharepoint storage capacity could be like this:
Product | skuId | Service Plan | GB | Count |
---|---|---|---|---|
Tenant | 1024 | 1 | ||
M365 E3 | SHAREPOINTSTANDARD | 10 | 20 | |
M365 E5 | SHAREPOINTENTERPRISE | 10 | 15 | |
Visio Client | ONEDRIVE_BASIC | 0.5 | 11 | |
Visio Plan 1 | ONEDRIVE_BASIC | 0.5 | 9 | |
Extra File Storage | SHAREPOINTSTORAGE | 10000 | 1 |
To create the list of products relevant to you, look up all product names and their service plans on
Graph Calls
To read the storage capacity programmatically, you can use the Graph endpoint subscribedSkus. This endpoint returns all the licenses and add-ons that your organization has.
https://graph.microsoft.com/v1.0/subscribedSkus
This will reveal a lot of details that you can use to form more precise and performant queries.
To retrieve only the minumum of information, you can call the endpoint with an id of the product.
The id of product is combined of tenantId and skuId separated by an underscore.
This query will gives me the amount of E5 licenses:
https://graph.microsoft.com/v1.0
/subscribedSkus
/12f488e2-8612-483f-ac92-10d86b99f9e3_c42b9cae-ea4f-4ab7-9717-81576235ccac
?$select=prepaidUnits
This query will gives me the Extra Storage (in case my organization has purchased it):
https://graph.microsoft.com/v1.0
/subscribedSkus
/12f488e2-8612-483f-ac92-10d86b99f9e3_99049c9c-6011-4908-bf17-15f496e6519d
?$select=prepaidUnits
Summary
To calculate the storage capacity in SharePoint Online is now possible, just get the purchased licenses and add-ons, and sum them up. There are some related topics that might be interesting here, but I am not going into it in this blog post, things like:
- Graph batching
- Graph Permissions
- Reading used capacity
- and others
Please let me know if you find this useful, if you have improvement suggestions to this approach or something else. Leave a comment below.