Requirement: Add file size column to SharePoint Online.
Are you looking to add a column to your SharePoint Online document library that displays the size of each file? Well, You can add the “File Size” column to any list view of the SharePoint Online document library to get the size of each file. Just follow these steps to add the file size column to SharePoint Online:
This adds the “File Size” column to the view and shows the size of each document in the view:
Please note, this is the size of the file without version history!
You can also get the size of each file from the properties of the file in Explorer view or from SharePoint Designer!
Adding a file size column to a SharePoint Online document library can be accomplished using PowerShell as well. Before you begin, you will need to have the PnP PowerShell module installed on your computer and be connected to your SharePoint Online site using the Connect-PnPOnline cmdlet.
Here is the PnP PowerShell to include the “File Size” field in the default view of a SharePoint Online document library (If it’s not already added!).
# Parameter $SiteURL = "https://crescent.sharepoint.com/sites/Retail" $ListName = "Documents" $ColumnName = "FileSizeDisplay" #InternalName Try < # Connect to PnP Online Connect-PnPOnline -Url $SiteURL -Interactive #Get the List Default View $List = Get-PnPList -Identity $ListName -Includes DefaultView #Get the List View from the list $ListView = Get-PnPView -List $ListName -Identity $List.DefaultView.Title #Check if view doesn't have the column already If($ListView.ViewFields -notcontains $ColumnName) < #Add Column to View $ListView.ViewFields.Add($ColumnName) $ListView.Update() Invoke-PnPQuery Write-host -f Green "Column '$ColumnName' Added to View!" >else < Write-host -f Yellow "Column '$ColumnName' Already Exists in View!" >> catchMy other post on getting the size of a file using PowerShell: How to Get File Size using PowerShell in SharePoint Online?