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. # 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 file
  14. $file=$item.File;
  15. $context.Load($file);
  16. $context.ExecuteQuery();
  17. Write-Host -ForegroundColor Yellow $file.Name " - Current Version: " $file.UIVersionLabel
  18. }

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.