Hi @Krishna Praveena Chirumamilla ,
versioning is now turned on by default when you create a new library or list, and it will automatically save the last 500 versions of a document.
Please try to use this PowerShell to get version history details.
#Set Parameters
$SiteURL="https://Crescent.sharepoint.com/sites/marketing"
$LibraryName="Branding"
$ReportOutput = "C:\Temp\VersionHistoryRpt.csv"
Try {
#Setup Credentials to connect
$Cred= Get-Credential
$Credentials = New-Object Microsoft.SharePoint.Client.SharePointOnlineCredentials($Cred.Username, $Cred.Password)
#Setup the context
$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$Ctx.Credentials = $Credentials
#Get the web & Library
$Web=$Ctx.Web
$Ctx.Load($Web)
$List = $Web.Lists.GetByTitle($LibraryName)
$Ctx.ExecuteQuery()
#Query to Batch process Items from the document library
$Query = New-Object Microsoft.SharePoint.Client.CamlQuery
$Query.ViewXml = "<View Scope='RecursiveAll'><Query><OrderBy><FieldRef Name='ID' /></OrderBy></Query><RowLimit>2000</RowLimit></View>"
Do {
$ListItems=$List.GetItems($Query)
$Ctx.Load($ListItems)
$Ctx.ExecuteQuery()
$Query.ListItemCollectionPosition = $ListItems.ListItemCollectionPosition
$VersionHistoryData = @()
#Iterate throgh each file - Excluding Folder Objects
Foreach ($Item in $ListItems | Where { $_.FileSystemObjectType -eq "File"})
{
$File = $Web.GetFileByServerRelativeUrl($Item["FileRef"])
$Ctx.Load($File)
$Ctx.Load($File.ListItemAllFields)
$Ctx.Load($File.Versions)
$Ctx.ExecuteQuery()
Write-host -f Yellow "Processing File:"$File.Name
If($File.Versions.Count -ge 1)
{
#Calculate Version Size
$VersionSize = $File.Versions | Measure-Object -Property Size -Sum | Select-Object -expand Sum
If($Web.ServerRelativeUrl -eq "/")
{
$FileURL = $("{0}{1}" -f $Web.Url, $File.ServerRelativeUrl)
}
Else
{
$FileURL = $("{0}{1}" -f $Web.Url.Replace($Web.ServerRelativeUrl,''), $File.ServerRelativeUrl)
}
#Send Data to object array
$VersionHistoryData += New-Object PSObject -Property @{
'File Name' = $File.Name
'Versions Count' = $File.Versions.count
'File Size' = ($File.Length/1KB)
'Version Size' = ($VersionSize/1KB)
'URL' = $FileURL
}
}
}
} While ($Query.ListItemCollectionPosition -ne $null)
#Export the data to CSV
$VersionHistoryData | Export-Csv $ReportOutput -NoTypeInformation
Write-host -f Green "Versioning History Report has been Generated Successfully!"
}
Catch {
write-host -f Red "Error Generating Version History Report!" $_.Exception.Message
}
Reference:
https://support.microsoft.com/en-us/office/how-versioning-works-in-lists-and-libraries-0f6cd105-974f-44a4-aadb-43ac5bdfd247
https://www.sharepointdiary.com/2016/12/sharepoint-online-version-history-report-using-powershell.html
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".