Share via

Can we get the total size of data in GB that have not been modified in the last 5 years

john john Pter 1,550 Reputation points
2025-12-10T17:42:43.6666667+00:00

Can we get the total size of data in GB that have not been modified in the last 5 years inside all the sharepoint sites?

thanks

Microsoft 365 and Office | SharePoint | Development
0 comments No comments

Answer accepted by question author

Teddie-D 16,130 Reputation points Microsoft External Staff Moderator
2025-12-11T04:06:00.1833333+00:00

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.  

Was this answer helpful?


1 additional answer

Sort by: Most helpful
  1. AI answer

    2025-12-10T17:42:54.9566667+00:00

    To determine the total size of data in SharePoint that has not been modified in the last 5 years, you can utilize the SharePoint dataset available through Microsoft Graph Data Connect. This dataset allows you to analyze the storage used by SharePoint sites and OneDrive accounts, including the ability to identify files that have not been modified within a specified timeframe.

    However, the specific total size calculation for data not modified in the last 5 years is not directly provided in the context. You would need to gather the data using the tools mentioned and perform the calculations based on the retrieved file information.


    References:

    AI-generated content may be incorrect. Read our transparency notes for more information.

    Was this answer helpful?

Your answer

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