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:
#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://crescenttech.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:
Get Change Log in SharePoint Online using PowerShell
SharePoint Online: Get Change Log using PowerShell SharePoint Online: Get Change Log using PowerShell Reviewed by Salaudeen Rajack on March 23, 2018 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.