SharePoint Online: Find Unused Lists based on Last Modified Date

Requirement: Find Unused SharePoint Online Lists and libraries based on the Last Modified Date.

How to Get the List Last Modified Date in SharePoint Online?

Are you looking for a way to clean up your SharePoint Online site? Maybe you’re finding that it’s becoming cluttered with unused lists. Or, possibly, you’d just like to eliminate any old or irrelevant lists before they start causing problems. In this article, we will show you how to find unused lists in SharePoint Online based on their last modified date. This can help free up storage space and improve performance on your site.

Go to the “Site Contents” page (https://tenant.sharepoint.com/_layouts/15/viewlsts.aspx) of the site either from the left navigation or from the site settings menu of the site, which lets you get the last modified date of all lists on the site.

sharepoint online list last modified date

SharePoint Online: Get List Last Modified Date using PowerShell

You can get the last modified date value of a SharePoint Online list using PnP PowerShell as,

#Set variables
$SiteURL = "https://crescent.sharepoint.com/sites/marketing"
$ListName = "Documents"

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

#Get the List Last modified date         
(Get-PnPList -Identity $ListName).LastItemUserModifiedDate

How about getting the last modified date for all lists on a site? This time, let’s use the CSOM 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"
 
#Variables 
$SiteURL ="https://crescent.sharepoint.com/sites/marketing"
 
Try {
    #Setup Credentials to connect
    $Cred= Get-Credential
  
    #Setup the context
    $Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
    $Ctx.Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
          
    #Get all lists from the Web
    $Lists = $Ctx.Web.Lists
    $Ctx.Load($Lists)
    $Ctx.ExecuteQuery()

    #Iterate through Lists
    ForEach($List in $Lists | Where {$_.hidden -eq $false})
    {
        #Get List last modified date
        Write-Host $List.Title  "Last Modified: " $List.LastItemUserModifiedDate
    }
}
Catch {
    write-host -f Red "Error:" $_.Exception.Message
}

Once you have identified unused lists, you can delete them from the SharePoint Online site: How to Delete a List in SharePoint Online using PowerShell?

In conclusion, finding unused lists based on the last modified date in SharePoint Online can help keep your site organized and free of unnecessary clutter. By using PowerShell, you can connect to SharePoint Online, retrieve the lists, and filter them by the last modified date. Then you can use the output to delete or move the unused lists to a different location. Additionally, If you decide to delete them, it’s important to verify that the list is not in use and that no important data is stored in it.

Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two-decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. He has held various positions including SharePoint Architect, Administrator, Developer and consultant, has helped many organizations to implement and optimize SharePoint solutions. Known for his deep technical expertise, He's passionate about sharing the knowledge and insights to help others, through the real-world articles!

6 thoughts on “SharePoint Online: Find Unused Lists based on Last Modified Date

  • I’m getting this error when I run the script on a site that has more than 50000 lists: Error: Exception calling “ExecuteQuery” with “0” argument(s): “The attempted operation is prohibited because it exceeds the list view threshold.”

    Reply
  • This appears to only get the last time an “Item” was modified. Is there any way to determine the last time the list structure was modified (new column added, indexing changed, etc.)???

    Reply
  • -Interactive in the first block allows me to login using MFA but the second block of code does not work for MFA.

    Reply
  • Hi.

    Can this script be tweaked to Track down files in a SharePoint Online site collection that have not been used or accessed for X years?

    Thank you.

    Reply

Leave a Reply

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