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.
- # Input Parameters
- $siteURL="https://c986.sharepoint.com/sites/dev"
- $listName="Demo List"
-
- # Connect to SharePoint Online site
- Connect-PnPOnline -Url $siteURL -Credentials (Get-Credential)
-
- # Get the list items
- $itemColl=Get-PnPListItem -List $listName
-
- # Get the context
- $context=Get-PnPContext
-
- # Loop through the items
- foreach($item in $itemColl)
- {
- # Get the item Versions
- $versionColl=$item.Versions;
- $context.Load($versionColl);
- $context.ExecuteQuery();
-
- #Loop through the versions
- foreach($version in $versionColl)
- {
- # Check if it is current version
- if($version.IsCurrentVersion)
- {
- Write-Host -ForegroundColor Yellow $item["Title"] " - Current Version: " $version.VersionLabel
- }
- }
- }
Open PowerShell window and run the following command.
folderlocation – GetCurrentVersion.ps1 file location
Run the following command
- >.\ GetCurrentVersion.ps1
Thus in this blog, you saw how to get the current SharePoint Online list item version using PnP PowerShell.