
Hi @Pradeep ,
You can restore previous versions of all files in the vault using PnP PowerShell:
#Function to Restore Previous Versions of all Files in a Library
Function Restore-PreviousVersion
{
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true,ValueFromPipeline=$true)][Microsoft.SharePoint.Client.List]$Library
)
Begin
{
$BatchSize = 2000
$global:Counter = 0
}
Process
{
#Get All Files from the Library in batches
$AllItems = Get-PnPListItem -List $Library -PageSize $BatchSize -Fields ID -ScriptBlock { Param($items) $global:counter += $items.Count; `
Write-Progress -PercentComplete ($global:Counter / ($Library.ItemCount) * 100) -Activity "Getting List Items of '$($_.Title)'" `
-Status "Processing Items $global:Counter to $($Library.ItemCount)";} | Where {$_.FileSystemObjectType -eq "File"}
Write-Progress -Activity "Completed Retrieving Items from List $($Library.Title)" -Completed
#Process All Files from the Library
$global:Counter = 1
ForEach($Item in $AllItems)
{
#Get File and Versions from the List Item
Get-PnPProperty -ClientObject $Item -Property File | Out-Null
Get-PnPProperty -ClientObject $Item.File -Property Versions | Out-Null
If($Item.File.Versions.Count -gt 0)
{
#Get the previous Version's Label
$VersionLabel = $Item.File.Versions[$Item.File.Versions.Count-1].VersionLabel
Write-Host "$(Get-Date) - ($($Counter)/$($AllItems.Count)) - Restoring version $VersionLabel for $($Item.File.Name)"
$item.File.Versions.RestoreByLabel($VersionLabel)
Invoke-PnPQuery
}
else
{
Write-Host "$(Get-Date) - ($($Counter)/$($AllItems.Count)) - Skipping $($Item.File.Name) as there are no previous versions!"
}
$Counter++
}
}
end
{
}
}
#Set Parameters
$SiteURL = "https://domain.sharepoint.com/sites/sitename"
$ListName = "LibraryName"
#Connect to SharePoint Online
Connect-PnPOnline -Url $SiteURL -Interactive
#Get the Library
$Library = Get-PnPList -Identity $ListName
#Call the function to Restore Previous Versions of all files
$Library | Restore-PreviousVersion
*
If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.