12

Is there a way to retrieve the amount of storage used and the quota limit for the Site Collection using the JSOM client or the REST web services?

1
  • I'm searching for the same thing but in SharePoint 2010 Aug 9, 2016 at 15:07

3 Answers 3

12

The REST query

https://<siteUrl>/_api/site/usage

will return the following:

{
    "d": {
        "Usage": {
            "__metadata": {
                "type": "SP.UsageInfo"
            },
            "Bandwidth": "0",
            "DiscussionStorage": "0",
            "Hits": "0",
            "Storage": "354721461",
            "StoragePercentageUsed": 0.0330360104329884,
            "Visits": "0"
        }
    }
}

Storage will give us "Storage Used"(in Bytes) not the "Total Storage" you can calculate the amount of storage used based on Storage and StoragePercentageUsed

3
  • This only gets the site collection size. On all subsites it returns the same number... any idea how we can get the size of each subsite?
    – JJD
    May 2, 2017 at 14:04
  • how can i get the "Maximum storage allowed "
    – Imen Turki
    Sep 25, 2019 at 14:30
  • 1
    I get permission denied. I am trying to get data for a site i belong to Sep 26, 2019 at 9:31
7

How to access information about site collection usage via CSOM

SP.UsageInfo object provides fields that are used to access information about site collection usage.

var context = new SP.ClientContext.get_current();
var site = context.get_site();
context.load(site,'Usage');  
context.executeQueryAsync(
    function() {

        var siteUsageInfo = site.get_usage();                   
        console.log(siteUsageInfo.get_storage());          
        console.log(siteUsageInfo.get_storagePercentageUsed());             
    },
    function(sender,args){
       console.log(args.get_message());
    }
);
0
-1
$cred = Get-Credential

$adminSiteURL = "spo admin url here"   
Connect-SPOService -Url $adminSiteURL -Credential $cred -ErrorAction Stop

$tenant = Get-SPOTenant -ErrorAction Stop   

$siteCollections = Get-SPOSite -Limit All -ErrorAction Stop 

$allocated = [math]::Round(($tenant.StorageQuota / 1024 / 1024), 2)

$used = [math]::Round((($siteCollections.StorageUsageCurrent | Measure-Object -Sum).Sum / 1024 / 1024), 2)

$data = [PSCustomObject]@{
        Allocated = $allocated
        Used      = $used
        PercentUsed = [math]::Round((($used / $allocated) * 100), 2)
}   

$data  | OGV
1
  • Could you please add more details to describe your script, BTW, the OP was asking about JSOM or REST API solution! Apr 22, 2020 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.