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"

$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

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

#Getting changes in the Change Log
$ChangeQuery = New-Object Microsoft.SharePoint.Client.ChangeQuery($true,$true)

#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:

Get Change Log in SharePoint Online using PowerShell

Salaudeen Rajack

Salaudeen Rajack - SharePoint Expert with Two decades of SharePoint Experience. Love to Share my knowledge and experience with the SharePoint community, through real-time articles!

Leave a Reply

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