当前位置:网站首页 > 更多 > 玩电脑 > 正文

[玩转系统] SharePoint Online:使用 PowerShell 获取更改日志

作者:精品下载站 日期:2024-12-14 14:57:46 浏览:13 分类:玩电脑

SharePoint Online:使用 PowerShell 获取更改日志


我们可以查询 SharePoint Online 中的更改日志,以获取对 SharePoint 内容数据库、网站集、网站或列表所做的更改的列表。这是我的 PowerShell 示例:

PowerShell 在 SharePoint Online 中获取更改日志:

要检索 SharePoint Online 更改日志并查看对列表或库所做的所有更改的列表(包括所做的更改和时间),您可以使用以下脚本:


#Load SharePoint CSOM Assemblies
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.dll"
Add-Type -Path "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\ISAPI\Microsoft.SharePoint.Client.Runtime.dll"

#Variables
$SiteURL="https://Crescent.sharepoint.com"
$ListName ="Documents"

#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)

#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials

#Get the web
$Web = $Ctx.Web
$Ctx.Load($Web)
$Ctx.ExecuteQuery()

#Get the List
$List = $Ctx.Web.Lists.GetByTitle($ListName)
$Ctx.Load($List)
$Ctx.ExecuteQuery()

#Getting changes in the Change Log
$ChangeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery($true,$true)
$ChangesCollection=$List.GetChanges($ChangeQuery)
$Ctx.Load($ChangesCollection)
$Ctx.ExecuteQuery()

#Get All Changes                
Write-Host "Number of Changes found:" $ChangesCollection.Count
$ChangesCollection | Select ChangeType, TypedObject, Time

Write-host "List Changes:"
#Iterate through the Changes Collection
ForEach($Change in $ChangesCollection)
{
    #Filter List Item changes
    If($Change -is [Microsoft.SharePoint.Client.ChangeItem])
    {
        $Change | Select ItemID, ChangeType, Time
    }
}

脚本结果:

[玩转系统] SharePoint Online:使用 PowerShell 获取更改日志

您需要 登录账户 后才能发表评论

取消回复欢迎 发表评论:

关灯