Got OneDrive version history for all users via PowerShell

Occasional Visitor

Hi Guys,


     Need OneDrive version history for all users, however, it's not available in the UI, seems only could do it via PowerShell,


Got below script from Microsoft support but it only for collect version history from one user,


anyone know how to modify it to collect version history from all users? thanks



#Set Variables
$SiteURL = ""
$LibraryName = "Documents"
$CSVPath = "C:\Temp\VersionHistoryRpt1.csv"

#Connect to SharePoint Online site
Connect-PnPOnline -Url $SiteURL -UseWebLogin

$VersionHistoryData = @()
#Iterate through all files
Get-PnPListItem -List $LibraryName -PageSize 500 | Where {$_.FieldValues.FileLeafRef -like "*.*"} | ForEach-Object {
Write-host "Getting Versioning Data of the File:"$_.FieldValues.FileRef
#Get FileSize & version Size
$FileSizeinKB = [Math]::Round(($_.FieldValues.File_x0020_Size/1KB),2)
$File = Get-PnPProperty -ClientObject $_ -Property File
$Versions = Get-PnPProperty -ClientObject $File -Property Versions
$VersionSize = $Versions | Measure-Object -Property Size -Sum | Select-Object -expand Sum
$VersionSizeinKB = [Math]::Round(($VersionSize/1KB),2)
$TotalFileSizeKB = [Math]::Round(($FileSizeinKB + $VersionSizeinKB),2)

#Extract Version History data
$VersionHistoryData+=New-Object PSObject -Property ([Ordered]@{
"File Name" = $_.FieldValues.FileLeafRef
"File URL" = $_.FieldValues.FileRef
"Versions" = $Versions.Count
"File Size (KB)" = $FileSizeinKB
"Version Size (KB)" = $VersionSizeinKB
"Total File Size (KB)" = $TotalFileSizeKB
$VersionHistoryData | Format-table -AutoSize
$VersionHistoryData | Export-Csv -Path $CSVPath -NoTypeInformation

#Read more:

0 Replies