I have created a custom list named “Demo List” in which versioning is enabled.

In this blog, you will see how to get the current SharePoint Online list item version using PnP PowerShell.

You can download setup files from the releases section of the PnP PowerShell repository. Copy the below script and paste it in a notepad. Save the file as GetCurrentVersion.ps1.
  1. # Input Parameters
  2. $siteURL="https://c986.sharepoint.com/sites/dev"
  3. $listName="Demo List"
  4. # Connect to SharePoint Online site
  5. Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)
  6. # Get the list items
  7. $itemColl=Get-PnPListItem -List $listName
  8. # Get the context
  9. $context=Get-PnPContext
  10. # Loop through the items
  11. foreach($item in $itemColl)
  12. {
  13. # Get the item Versions
  14. $versionColl=$item.Versions;
  15. $context.Load($versionColl);
  16. $context.ExecuteQuery();
  17. #Loop through the versions
  18. foreach($version in $versionColl)
  19. {
  20. # Check if it is current version
  21. if($version.IsCurrentVersion)
  22. {
  23. Write-Host -ForegroundColor Yellow $item["Title"] " - Current Version: " $version.VersionLabel
  24. }
  25. }
  26. }

Open PowerShell window and run the following command.

  1. >cd "<folderlocation>"

folderlocation – GetCurrentVersion.ps1 file location

Run the following command

  1. >.\ GetCurrentVersion.ps1

Thus in this blog, you saw how to get the current SharePoint Online list item version using PnP PowerShell.