GetSPOListChange.ps1


<#PSScriptInfo
 
.VERSION 1.0.0.1
 
.GUID 50c76a3e-360d-493b-89a8-55a24b499a1f
 
.AUTHOR Chendrayan Venkatesan
 
.COMPANYNAME
 
.COPYRIGHT
 
.TAGS SharePointOnline,CSOM,PowerShell
 
.LICENSEURI
 
.PROJECTURI
 
.ICONURI
 
.EXTERNALMODULEDEPENDENCIES
 
.REQUIREDSCRIPTS
 
.EXTERNALSCRIPTDEPENDENCIES
 
.RELEASENOTES
 
 
#>


<#
 
.DESCRIPTION
 Retrieves changes from the given SharePoint Online List
 
#>
 
param
(
    [Parameter(Mandatory)]
    $Url,

    [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
    $Title,

    [Parameter(Mandatory)]
    [System.Management.Automation.CredentialAttribute()]
    [pscredential]
    $Credential
)
# Change the path where your CSOM Assemblies are located. For this script Microsoft.SharePoint.Client.dll is only assembly required.
Import-Module 'C:\Program Files\NuGet\Packages\Microsoft.SharePointOnline.CSOM.16.1.5312.1200\lib\net45\Microsoft.SharePoint.Client.dll'
function Get-xSPOListChange
{
<#
.SYNOPSIS
    Retrieves SharePoint Online List or Document Library Changes using ChangeQuery Class.
.DESCRIPTION
    Get-xSPOListChange retrieves all the changes occurred in the given SharePoint Online List or Document Library.
     
.EXAMPLE
    C:\PS> Get-xSPOListChange -Url https://chensoffice365.sharepoint.com -Title MyList -Credential "Admin@contoso.onmicrosoft.com"
    Get all the changes occurred in the List "MyList"
.EXAMPLE
    C:\PS> "Demo123" , "MyList" | Get-xSPOListChange -Url https://contoso.sharepoint.com -Credential "Admin@contoso.onmicrosoft.com"
    Get all the changes occurred in the Lists "MyList" and "Demo123"
.EXAMPLE
    C:\PS> "Demo123" , "Documents" | Get-xSPOListChange -Url https://contoso.sharepoint.com -Credential "Admin@contoso.onmicrosoft.com"
    Get all the changes occurred in the List "Demo123" and Document Library "Documents"
.NOTES
    To know more about change query refer Related Link using help Get-xSPOListChange
.LINK
    https://msdn.microsoft.com/library/office/microsoft.sharepoint.client.changequery.aspx
#>

    [CmdletBinding()]
    param
    (
        [Parameter(Mandatory)]
        $Url,

        [Parameter(Mandatory,ValueFromPipeline,ValueFromPipelineByPropertyName)]
        $Title,

        [Parameter(Mandatory)]
        [System.Management.Automation.CredentialAttribute()]
        [pscredential]
        $Credential
    )
    process
    {
        $SPOClientContext = [Microsoft.SharePoint.Client.ClientContext]::new($Url)
        $SPOClientContext.Credentials = [Microsoft.SharePoint.Client.SharePointOnlineCredentials]::new($Credential.UserName,$Credential.Password)
        $List = $SPOClientContext.Web.Lists.GetByTitle($Title)
        $SPOClientContext.Load($List)
        $ChangeQuery = [Microsoft.SharePoint.Client.ChangeQuery]::new($true,$true)
        $ListChanges = $List.GetChanges($ChangeQuery)
        $SPOClientContext.Load($ListChanges)
        $SPOClientContext.ExecuteQuery()
        $SPOClientContext.Dispose()
        foreach($change in $ListChanges)
        {
            $change 
        }
    }
}