SharePoint Online: Get Change Log using PowerShell
We can query Change Log in SharePoint Online to get a list of changes made to a SharePoint content database, site collection, site, or list. Here is my PowerShell example:
PowerShell to Get Change Log in SharePoint Online:
To retrieve the SharePoint Online change log and view a list of all changes made to your list or library, including what changes have been made and when, you can use this 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"
$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
}
}
Script result: