Retrieve SharePoint List Item Versions in SharePoint Online using PnP
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
$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
Post a Comment