How To Get The Current Document Version In SharePoint Online Using PnP PowerShell

I have a document library named “Documents” in which versioning is enabled.

 

In this blog, you will see how to get the current document version in SharePoint Online 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="Documents"   
  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 file  
  18.     $file=$item.File;  
  19.     $context.Load($file);      
  20.     $context.ExecuteQuery();      
  21.     Write-Host -ForegroundColor Yellow $file.Name " - Current Version: " $file.UIVersionLabel    
  22. }  

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 document version in SharePoint Online using PnP PowerShell.