Retrieve programmatically SharePoint Online storage space

Oleksii Kolinko 6 Reputation points
2021-01-08T11:33:29.507+00:00

How can I retrieve programmatically SharePoint Online allocated (purchased) storage space of the whole tenant, which is visualized "In the upper right of the page":
https://learn.microsoft.com/en-us/sharepoint/manage-site-collection-storage-limits

In report below, it is possible to retrieve used storage space, but not the allocated.

https://learn.microsoft.com/en-us/graph/api/reportroot-getsharepointsiteusagestorage?view=graph-rest-beta

Microsoft 365 and Office | SharePoint | For business | Windows
Developer technologies | C#
{count} votes

3 answers

Sort by: Most helpful
  1. Oleksii Kolinko 6 Reputation points
    2021-01-11T14:17:29.517+00:00
    1 person found this answer helpful.

  2. Martin Day 151 Reputation points
    2021-01-11T09:40:26.4+00:00

    Hi

    You can use Get-SPOTenant which will return a property called StorageQuota.

    Docs article here.

    Hope this helps!

    Martin

    0 comments No comments

  3. Emily Du-MSFT 51,836 Reputation points Microsoft External Staff
    2021-01-11T10:04:24.657+00:00

    Try below PowerShell.

    #Config Parameters  
    $AdminSiteURL="https://testLZ-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  
    

    Reference:
    https://www.sharepointdiary.com/2017/04/sharepoint-online-get-storage-size-quota-report-using-powershell.html


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.