SharePoint Online: View Folder Size using PowerShell

Requirement: Get a Folder Size in SharePoint Online.

How to Check a Folder Size in SharePoint Online?

Managing SharePoint content can be a daunting task, especially when you have to find out what size your folders are. You will need to know the total size of your folder to determine how much space is left on your site and for future data storage allocation. In this blog post, I’ll show you how to check the size of a folder in SharePoint Online from the site settings page and with PowerShell script.

How to check folder size in SharePoint Online? To view folder size in SharePoint Online, go to:

  1. Navigate to the site >> Click on Settings gear >> Site Settings >> Click on the “Storage Metrics” link under “Site Collection Administration”.
  2. On the storage metrics page, click on the document library to navigate to the location where the target folder is stored.
    sharepoint online get folder size

The storage metrics page shows the size of each folder and file (including version history size). It is worth mentioning that the storage metrics page data is not real-time data! It takes a while for a background timer job to run and populate this data.

SharePoint Online: Get Folder Size using PowerShell

As the amount of data stored in SharePoint libraries grows, it is important to monitor and manage the size of the folders and libraries. One way to do this is by using PowerShell, which provides a powerful scripting environment to automate tasks and retrieve information about SharePoint Online.

How to find folder size in SharePoint Online? Well, let’s check folder size for all folders in a SharePoint Online site using the PowerShell script:

#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"
#Function to Get the size of a Folder in SharePoint Online
Function Get-SPOFolderSize([Microsoft.SharePoint.Client.Folder]$Folder)
        #Get all Files and Subfolders from the folder

        $FolderSize = 0
        ForEach($File in $Folder.Files | Where {-Not($_.Name.EndsWith(".aspx"))})
            #Get File versions
            If($File.Versions.Count -ge 1)
                #Calculate Version Size
                $VersionSize = $File.Versions | Measure-Object -Property Size -Sum | Select-Object -expand Sum                                
            $FileSize =  [Math]::Round((($File.Length) + $VersionSize)/1KB, 2)
            If($FileSize -gt 0)
                Write-host "`tSize of the File '$($File.Name)' "$FileSize

            #Get File Size
            $FolderSize += $FileSize

        If($FolderSize -gt 0)
            Write-host -f Yellow "Total Size of the Folder '$($Folder.ServerRelativeUrl)' (KB): " -NoNewline
            $FolderSize= [Math]::Round($FolderSize/1KB, 2)
            Write-host $FolderSize
        #Process all Sub Folders
        ForEach($Folder in $Folder.Folders | Where {-Not($_.Name.StartsWith("_") -or $_.Name -eq "Forms")})
            #Call the function recursively
            Get-SPOFolderSize $Folder
    Catch [System.Exception]
        Write-Host -f Red "Error:"$_.Exception.Message
$SiteURL = ""

#Get credentials to connect to SharePoint Online Admin Center
$Cred = Get-Credential
#Set up the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Get the Web
$Web = $Ctx.Web
$RootFolder = $Web.RootFolder
#Call the function to get Subsite size
Get-SPOFolderSize -Folder $RootFolder

How to view folder size in SharePoint Online using PnP PowerShell?

Instead of summarizing the size of each file and its versions, we can directly get the folder size (Files + Versions) from its property: SMTotalSize!

$SiteURL = "" 
$FolderSiteRelativeURL = "/Branding/Active"

#Connect to PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the folder
$Folder = Get-PnPFolder -Url $FolderSiteRelativeURL -Includes ListItemAllFields

#Get the total Size of the folder - with versions
Write-host "Size of the Folder:" $([Math]::Round(($Folder.ListItemAllFields.FieldValues.SMTotalSize.LookupId/1KB),2))

Here is another approach to obtaining the folder size from site storage metrics:

#Subsite URL
$SiteURL = ""

#Connect PnP Online
Connect-PnPOnline -Url $SiteURL -Interactive

#Get the folder size from storage metrics
$FolderSize = Get-PnPFolderStorageMetric -FolderSiteRelativeUrl "Shared Documents" | Select -ExpandProperty TotalSize
$FolderSize = [Math]::Round($FolderSize/1MB, 2)
Write-host "Total size of the Folder: $FolderSize MB" 

How about finding the sizes of all folders in a document library?

$SiteURL = "" 
$ListName = "Branding"
$CSVFile = "C:\Temp\FolderSize.csv"

Try {
    #Connect to PnP Online
    Connect-PnPOnline -Url $SiteURL -Interactive
    #Get all folders from the document library
    $Folders = Get-PnPListItem -List $ListName -PageSize 2000 | Where { $_.FileSystemObjectType -eq "Folder" }
    #Calculate Folder Size from files
    $FolderSizeData = @()
    $Folders | ForEach-Object {
        #Extract Folder Size data
        $FolderSizeData += New-Object PSObject -Property  ([Ordered]@{
            "Folder Name"  = $_.FieldValues.FileLeafRef
            "URL" = $_.FieldValues.FileRef        
            "Size" = $_.FieldValues.SMTotalSize.LookupId
    $FolderSizeData | Format-Table
    $FolderSizeData | Export-csv $CSVFile -NoTypeInformation
    #Calculate the Total Size of Folders
    $FolderSize = [Math]::Round((($FolderSizeData | Measure-Object -Property "Size" -Sum | Select-Object -expand Sum)/1KB),2)
    Write-host -f Green ("Total Size: {0}" -f $FolderSize)
Catch {
    Write-Host -f Red "Error:"$_.Exception.Message


In this tutorial, we discussed how to retrieve the size of a folder in SharePoint Online using the storage metrics page and PowerShell. By using the SharePoint Client Side Object Model (CSOM) and a PnP PowerShell script, we were able to retrieve the size of a folder and its subfolders, providing valuable information for managing the storage usage of a SharePoint Online environment. This method can be used as part of a larger automation process, helping to keep your SharePoint environment organized and optimized.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

One thought on “SharePoint Online: View Folder Size using PowerShell

  • Found this entry very helpful and tried to use the approach with in one of our largest sites where we do no longer get folder sizes in storman.aspx. We found that for lots of folders we did not get a resonable value. While we analysed that, we saw that depending on the reported size the value for the size (observation was >than 2GB ?) could be found either in $Folder.ListItemAllFields.FieldValues.SMTotalSize.LookupId or directly in $Folder.ListItemAllFields.FieldValues.SMTotalSize which leads to following code change:
    $folder = Get-PnPFolder -Url $targetFolder -Includes ListItemAllFields -Connection $connection – if (($Folder.ListItemAllFields.FieldValues.SMTotalSize.GetType()).Name -eq “String”) {
    else {


Leave a Reply

Your email address will not be published. Required fields are marked *