Retrieve SharePoint List Item Versions in SharePoint Online using PnP

Retrieve List Item Versions in SharePoint Online using PnP @SharePointWidgets.com

 

In many cases, we need to identify the versions of the SharePoint List Item. So here is the way to get all the versions of the item using PnP.


function Get-ItemVersion {
     param ($spURL, $spListTitle)
    
     $checked = ([char]8730)
    
     Write-Host "Creating connection to the SharePoint Online....." -ForegroundColor Yellow -NoNewline
    $spConnection = Connect-PnPOnline -Url $spURL -UseWebLogin -ReturnConnection -ErrorAction Stop
    Write-Host $checked -ForegroundColor Green

     Write-Host "Reading list items from '$listTitle'....." -ForegroundColor Yellow -NoNewline
     $listItems = Get-PnPListItem -List $spListTitle -PageSize 5000  -Connection $spConnection -ErrorAction Stop     
     Write-Host $checked" ($($listItems.Count) in $(((Get-Date- $start).Seconds) sec)" -ForegroundColor Green

     $listItems | ForEach-Object {
         $listItem = $_

         $versions = Get-PnPProperty -ClientObject $listItem -Property Versions

# Get the latest version
         $version = $versions | Sort-Object { $_.VersionId } | Select-Object -Last 1

         # To access the field Values
         $id = $version.FieldValues["ID"]        
    }
}

In this way, you can access all the versions of the SharePoint List Item.


Happy Coding..!!




Comments

Popular posts from this blog

Rename Folder using Microsoft Flow / Power Automate in a Document Library in SharePoint Online

Power Automate: How to Add "New Line" to the text in SharePoint multiline text field

Power Automate: Rename file in SharePoint Online