How To Get The Current SharePoint Online List Item Version Using PnP PowerShell

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.   
  5. Connect to SharePoint Online site  
  6. Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)  
  7.   
  8. # Get the list items  
  9. $itemColl=Get-PnPListItem -List $listName  
  10.   
  11. # Get the context  
  12. $context=Get-PnPContext  
  13.   
  14. # Loop through the items  
  15. foreach($item in $itemColl)  
  16. {     
  17.     # Get the item Versions  
  18.     $versionColl=$item.Versions;  
  19.     $context.Load($versionColl);      
  20.     $context.ExecuteQuery();  
  21.   
  22.     #Loop through the versions  
  23.     foreach($version in $versionColl)  
  24.     {  
  25.         # Check if it is current version  
  26.         if($version.IsCurrentVersion)  
  27.         {  
  28.             Write-Host -ForegroundColor Yellow $item["Title"" - Current Version: " $version.VersionLabel  
  29.         }  
  30.     }     
  31. }  

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.