Hi @john john Pter
Thank you for posting your question in the Microsoft Q&A forum.
SharePoint Online doesn’t provide a built‑in report that shows the total size of files that haven’t been modified for a long period of time. However, you can retrieve this information using either PnP PowerShell or Microsoft Graph, since every file exposes both its LastModifiedDateTime and Size.
Below are two practical approaches:
1.Use PnP PowerShell
You can query your library, filter by last modified date, and sum the file sizes.
Install-Module PnP.PowerShell
Import-Module PnP.PowerShell
# Connect to the SharePoint site
Connect-PnPOnline -Url "https://yourtenant.sharepoint.com/sites/yoursite" -Interactive -ClientID <your application ID>
# Cutoff date = today minus 5 years
$cutoffDate = (Get-Date).AddYears(-5)
$totalSize = 0
$lists = Get-PnPList | Where-Object { $_.BaseType -eq "DocumentLibrary" -and $_.Hidden -eq $false }
foreach ($list in $lists) {
$items = Get-PnPListItem -List $list.Title -PageSize 500 -Fields "FileRef","File_x0020_Size","Modified"
foreach ($item in $items) {
if ($item["Modified"] -lt $cutoffDate) {
$totalSize += [int]$item["File_x0020_Size"]
}
}
}
$totalSizeGB = [math]::Round($totalSize / 1GB, 2)
Write-Host "Total size of files not modified in 5 years: $totalSizeGB GB"
To connect PnP PowerShell, you may refer to How to connect to PnP Online with Interactive Authentication.
Note: Microsoft is providing this information as a convenience to you. The sites are not controlled by Microsoft. Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. Please make sure that you completely understand the risk before retrieving any suggestions from the above link.
2.Use Microsoft Graph API
GET /sites/{site-id}/drives/{drive-id}/root/children
Graph also exposes file metadata, but you must enumerate everything yourself:
-Recursively walk the entire drive (root > folders > subfolders > files).
-For each file, compare lastModifiedDateTime with your 5‑year cutoff.
-Add up the size values for all matching files.
You’ll need to continue paging and drilling into folders until all items are processed.
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
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.