网站搜索

SharePoint Online:根据上次修改日期查找未使用的列表


要求:根据上次修改日期查找未使用的 SharePoint Online 列表和库。

如何获取 SharePoint Online 中列表的上次修改日期?

您是否正在寻找清理 SharePoint Online 网站的方法?也许您发现它变得杂乱无章,充满了未使用的列表。或者,您可能只是想在任何旧的或不相关的列表开始引起问题之前将其删除。在本文中,我们将向您展示如何根据上次修改日期在 SharePoint Online 中查找未使用的列表。这有助于释放存储空间并提高站点的性能。

从左侧导航或从网站的网站设置菜单转到网站的“网站内容”页面 (https://tenant.sharepoint.com/_layouts/15/viewlsts.aspx)网站,它可以让您获取网站上所有列表的最后修改日期。

SharePoint Online:使用 PowerShell 获取列表上次修改日期

您可以使用 PnP PowerShell 获取 SharePoint Online 列表的上次修改日期值,如下所示:


#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

获取网站上所有列表的最后修改日期怎么样?这次,我们使用 CSOM PowerShell 脚本:


#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 网站中删除它们:如何使用 PowerShell 删除 SharePoint Online 中的列表?

总之,根据 SharePoint Online 中的上次修改日期查找未使用的列表可以帮助您的网站保持井井有条,避免不必要的混乱。通过使用 PowerShell,您可以连接到 SharePoint Online、检索列表并按上次修改日期对其进行筛选。然后,您可以使用输出来删除未使用的列表或将其移动到其他位置。此外,如果您决定删除它们,请务必验证该列表未被使用并且其中没有存储重要数据。

相关文章