Home » Blog » SharePoint Online » How to Find Large Files in SharePoint Online? [A Quick Guide]

How to Find Large Files in SharePoint Online? [A Quick Guide]

author
Published By Raj Kumar
Anuraag Singh
Approved By Anuraag Singh
Published On August 28th, 2024
Reading Time 8 Minutes Reading

Summary:- If you are searching for an easy way to find large files in SharePoint Online. Then you are exactly where you need to be. Here we will discuss what are numerous methods through them, you can search large files in SharePoint.

Because of the increasing demand for SharePoint in organizations, it is used at an alarming rate. Despite its enormous features, one of its key features to manage documents makes it more purposeful. However, due to its extensive use, sometimes the document libraries own the large files.

As a result, the performance of search is affected, and managing large lists and libraries in SharePoint also becomes cumbersome for the administrators. So, if you want to audit SharePoint site or make strategies to handle large files. Then first you have to figure out how to know all your large files in SharePoint Online. So, let’s start the write-up to help you out with this dilemma.

How to Search for Large Files in SharePoint Using Storage Metrics?

Follow the below steps in SharePoint Admin Center to know the consumption of the files in SharePoint.

  • Step 1. Move to the SharePoint Online site collection.
  • Step 2. Open Settings and then hit Site Settings.
  • Step 3. From the Site settings page, open the Storage Metrics.
  • Step 4. Analyze the storage metrics of the site
  • Step 5. You can also navigate the files and folders to see their storage consumption.

Check the Files Size in SharePoint Using Size Property

You can find the large files based on their size just by searching them by using the size property. It is a built-in option that can get you accurate results. You just need to type the query like:-

  • Size > 5000000, it will show you files greater than 5 MB.
  • Size > 100000 AND filetype:pdf, it will show you the PDF files having file size greater than 1 MB.

Find All Large Files in the Site Collection Using PowerShell

This script will generate the report of all large files having a size larger than 1 GB.

#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 find large files on the web

Function Find-SPOAllLargeFiles([String]$SiteURL, [Microsoft.SharePoint.Client.Folder]$Folder)
{
Write-host -f Yellow "Processing Folder: $($SiteURL)$($Folder.ServerRelativeURL)"
Try {
$ResultofLargeFile = @()
#Get all Files from the folder
$FilesInput = $Folder.Files
$CtxtLoad($FilesInput)
$Ctxt.ExecuteQuery()

#Iterate through each file and check the size
Foreach($File in $FilesInput)
{
If($File.length -gt 1GB)
{
$URLofFile= $SiteURL+$File.ServerRelativeURL
$Resulting = New-Object PSObject
$Resulting | Add-Member NoteProperty FileName($File.Name)
$Resulting | Add-Member NoteProperty URLofFile($URLofFile)
$Resulting | Add-Member NoteProperty Size-MB([math]::Round($File.Length/1MB))

#Add the result to an Array
$ResultofLargeFile += $Resulting

Write-host -f Green "Found a File '$($File.Name)' with Size $([math]::Round($File.Length/1MB))MB"

#Export the result to CSV file
$ResultofLargeFile | Export-CSV $ReportofOutput -NoTypeInformation -Append
}
}

#Process all Sub Folders
$FoldersSub = $Folder.Folders
$Ctxt.Load($FoldersSub)
$Ctxt.ExecuteQuery()
Foreach($Folder in $FoldersSub)
{
#Exclude "Forms" and Hidden folders
If( ($Folder.Name -ne "Forms") -and (-Not($Folder.Name.StartsWith("_"))))
{
#Call the function recursively
Find-SPOAllLargeFiles -SiteURL $SiteURL -Folder $Folder
}
}
}
Catch {
write-host -f Red "Error Finding Large Files!" $_.Exception.Message
}
}

#Function to Generate Reports on Large Files in a SharePoint Online Site Collection
Function Get-SPOAllLargeFilesRpt($SiteURL)
{
#Setup the context
$Ctxt = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctxt.Credentials = $StoreCredentials

#Get the web from the given URL and its subsites
$Web = $Ctxt.web
$Ctxt.Load($Web)
$Ctxt.Load($web.Webs)
$Ctxt.executeQuery()

#Call the function to get large files of the web
Find-SPOAllLargeFiles -SiteURL $SiteURL -Folder $Web.RootFolder

#Iterate through each subsite of the current web and call the function recursively
foreach ($Subweb in $web.Webs)
{
#Call the function recursively to process all subsites underneath the current web
Get-SPOAllLargeFilesRpt($Subweb.url)
}
}

#Config Parameters
$SiteURL="https://crescent.sharepoint.com"
$ReportofOutput="C:\temp\LargeFilesRpt.csv"

#Setup Credentials to connect
$Credt= Get-Credential
$StoreCredentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Credt.Username, $Credt.Password)

#Delete the Output Report, if exists
if (Test-Path $ReportofOutput) { Remove-Item $ReportofOutput }

#Call the function
Get-SPOAllLargeFilesRpt $SiteURL

PowerShell Commands to Find Large Files in SharePoint Online Site Efficiently

Find out the files in SharePoint Online site taking more than 2 GB of space.

#Config Variables
$SharePointSiteURL = "enter URL"
$FilePathCSV = "C:\Temp\LargeFiles.csv"

#Connect to PnP Online
Connect-PnPOnline -Url $SharePointSiteURL -Credentials (Get-Credential)

#Get all document libraries
$DataofFile = @()
$DocLibraries = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False}

#Iterate through document libraries
ForEach ($List in $DocLibraries)
{
Write-host " Library is Processing:"$List.Title -f Yellow

#Get All Files of the library with size > 2GB
$AllFiles = Get-PnPListItem -List $List -PageSize 500 | Where {($_.FieldValues.FileLeafRef -like "*.*") -and ($_.FieldValues.SMTotalFileStreamSize/1MB -gt 100)}

#Collect data from each files
ForEach ($File in $AllFiles)
{
$DataofFile += [PSCustomObject][ordered]@{
Library = $List.Title
FileName = $File.FieldValues.FileLeafRef
URL = $File.FieldValues.FileRef
CreatedBy = $File.FieldValues.Author.Email
Created = $File.FieldValues.Created
ModifiedBy = $File.FieldValues.Editor.Email
Modified = $File.FieldValues.Modified
Size = [math]::Round(($File.FieldValues.SMTotalFileStreamSize/1MB),2)
}
}
}
#Export Files data to CSV File
$DataofFile | Sort-object Size -Descending
$DataofFile | Export-Csv -Path $FilePathCSV -NoTypeInformation

Search for Large Files in SharePoint Online of the Entire Tenant

Let’s find the size of all the files of all SharePoint sites in a tenant.

#Config Variables
$URLofTenantAdmin = "enter URL"
$FilePathinCSV = "C:\Temp\LargeFiles.csv"

#Connect to Admin Center using PnP Online
Connect-PnPOnline -Url $URLofTenantAdmin -Interactive

#Delete the Output Report, if exists
if (Test-Path $FilePathinCSV) { Remove-Item $FilePathinCSV }

#Get All Site collections - Exclude: Seach Center, Redirect site, Mysite Host, App Catalog, Content Type Hub, eDiscovery and Bot Sites
$CollectionsofSite = Get-PnPTenantSite | Where { $_.URL -like '*/sites*' -and $_.Template -NotIn ("SRCHCEN#0", "REDIRECTSITE#0", "SPSMSITEHOST#0", "APPCATALOG#0", "POINTPUBLISHINGHUB#0", "EDISC#0", "STS#-1")}

#Get All Large Lists from the Web - Exclude Hidden and certain lists
$ExcludedAllLists = @("Form Templates", "Preservation Hold Library","Site Assets", "Pages", "Site Pages", "Images",
"Site Collection Documents", "Site Collection Images","Style Library")

$SiteCount = 1
#Loop through each site collection
ForEach($Site in $CollectionsofSite)
{
#Display a Progress bar
Write-Progress -id 1 -Activity "Processing Site Collections" -Status "Processing Site: $($Site.URL)' ($SiteCount of $($CollectionsofSite.Count))" -PercentComplete (($SiteCount / $CollectionsofSite.Count) * 100)

#Connect to the site
Connect-PnPOnline -Url $Site.URL -Interactive

#Get all document libraries
$DocLibraries = Get-PnPList | Where-Object {$_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $False -and $_.Title -notin $ExcludedAllLists -and $_.ItemCount -gt 0}

$CounterforList = 1
#Iterate through document libraries
ForEach ($List in $DocLibraries)
{
$global:counter = 0
$FileData = @()

Write-Progress -id 2 -ParentId 1 -Activity "Processing Document Libraries" -Status "Processing Document Library: $($List.Title)' ($CounterforList of $($DocLibraries.Count))" -PercentComplete (($CounterforList / $DocLibraries.Count) * 100)

#Get All Files of the library with size > 100MB
$Files = Get-PnPListItem -List $List -Fields FileLeafRef,FileRef,SMTotalFileStreamSize -PageSize 500 -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress -Id 3 -parentId 2 -PercentComplete ($global:Counter / ($List.ItemCount) * 100) -Activity "Getting List Items of '$($List.Title)'" -Status "Processing Items $global:Counter to $($List.ItemCount)";} | Where {($_.FileSystemObjectType -eq "File") -and ($_.FieldValues.SMTotalFileStreamSize/1MB -gt 100)}

#Collect data from each files
ForEach ($File in $Files)
{
$FileData += [PSCustomObject][ordered]@{
Library = $List.Title
FileName = $File.FieldValues.FileLeafRef
URL = $File.FieldValues.FileRef
Size = [math]::Round(($File.FieldValues.SMTotalFileStreamSize/1MB),2)
}
}

#Export Files data to CSV File
$FileData | Sort-object Size -Descending
$FileData | Export-Csv -Path $FilePathinCSV -NoTypeInformation -Append
$CounterforList++
#Write-Progress -Activity "Completed Processing List $($List.Title)" -Completed -id 2

}
$SiteCount++
}

Find Large Files in SharePoint Along with their Version History Size

Get the data of all the files of a document library that exceeds the specific size limit along with their version history sizes.

#Parameters
$URLofSite = "enter URL”
$ListName = "Documents"
$CSVPath = "C:\Temp\FundLargeFilesRpt.csv"
$MinSizeofFile = 100 #100 MB

#Connect to PnP Online
Connect-PnPOnline -Url $URLofSite -Interactive

#Get the Document Library
$List = Get-PnPList -Identity $ListName

$global:counter=0
$ListItemCounter = $List.ItemCount
#Get All Items from the List
$ListAlIItems = Get-PnPListALLItem -List $ListName -Fields FileRef, SMTotalFileStreamSize, SMTotalSize,_UIVersionString -PageSize 2000 -ScriptBlock { Param($items) $global:counter += $items.Count; Write-Progress `
-PercentComplete ($global:Counter / ($ListItemCounter) * 100) -Activity "Getting Files of '$($List.Title)'" `
-Status "Processing Files $global:Counter of $($ListItemCounter)";} | Where {($_.FileSystemObjectType -eq "File")}
Write-Progress -Activity "Completed Retrieving Files!" -Completed

$FileData = @()
$CheckItemCount = 1
$TotalFiles = $ListALLItems.count
#Collect data from each files
ForEach ($Item in $ListItems)
{
#Display a Progress bar
Write-Progress -Activity "Processing Files ($CheckItemCount of $TotalFiles)" -Status "Processing File: $($Item.FieldValues.FileRef)'" -PercentComplete (($CheckItemCount / $TotalFiles) * 100)

If (($Item.FieldValues.SMTotalSize.LookupId/1MB) -gt $MinSizeofFile)
{
write-host $Item.FieldValues.FileRef
$FileData += [PSCustomObject][ordered]@{
FileName = $Item.FieldValues.FileLeafRef
URL = $Item.FieldValues.FileRef
Created = $Item.FieldValues.Created
Modified = $Item.FieldValues.Modified
FileSize = [math]::Round(($Item.FieldValues.SMTotalFileStreamSize/1MB),2)
TotalSize = [math]::Round(($Item.FieldValues.SMTotalSize.LookupId/1MB),2)
LastVersion = $Item.FieldValues._UIVersionString
}
}
$CheckItemCount++
}
#Export Files data to CSV File
$FileData | Export-Csv -Path $CSVPath -NoTypeInformation

After finding the large files in your SharePoint tenant. Now you can use the Expert’s Handpicked SharePoint Migration Tool to move them to another site.

Download Now Purchase Now

By using this tool, you can easily copy document library from one site to another. Due to this, you do not need to delete them, and managing the small-sized files in SharePoint also becomes easier for you.

Final Words

In this comprehensive write-up, we have explained the different methods to find large files in SharePoint Online. You can pick any of the methods that can fulfill your requirements. Now you can easily optimize your SharePoint environment by knowing the large files. In addition, we have also elaborated a solution to simplify the management of SharePoint without deleting the large files.

Connect With Us

+9111-28084986