SharePoint Online: Find Unused Lists based on Last Modified Date

Requirement: Find Unused SharePoint Online Lists based on Last Modified Date

How to Get the List Last Modified Date in SharePoint Online?
Go to the "Site Contents" page (https://tenant.sharepoint.com/_layouts/15/viewlsts.aspx) of the site either from left navigation or from site settings menu of the site, which lets you to get last modified date of all lists in the site.
sharepoint online list last modified date

SharePoint Online: Get List Last Modified Date using PowerShell
You can get 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 -UseWebLogin 

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

How about getting the last modified date for all lists in a site? This time let's use 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
}
SharePoint Online: Find Unused Lists based on Last Modified Date SharePoint Online: Find Unused Lists based on Last Modified Date Reviewed by Salaudeen Rajack on March 29, 2019 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.