Forum Discussion
Nigel_Price9911
Feb 12, 2018Iron Contributor
How Do I get the version of a file using PnP Powershell
Hi
I am trying to get the version of a file in a document library using PnP Powershell.
Connect-PnPOnline -Url <url>
$ListItems = Get-PnPListItem -List <MyDocLibrary>
for each ($item...
AlyaKoni
Sep 23, 2020Copper Contributor
Nigel_Price9911 For SharePoint Online I'm using following code:
Get-PnPFile -Url $item.ServerRelativeUrl -Path $destinationFolderPath -AsFile -Force # Latest version
$ctx= Get-PnPContext
$ctx.Load($item.Versions)
$ctx.ExecuteQuery()
foreach ($version in $item.Versions)
{
$versionValue = $version.VersionLabel
$str = $version.OpenBinaryStream()
$ctx.ExecuteQuery()
$filename = (Split-Path $item.ServerRelativeUrl -Leaf) + "." + $versionValue
$filepath = Join-Path $destinationFolderPath $filename
$fs = New-Object IO.FileStream $filepath ,'Append','Write','Read'
$str.Value.CopyTo($fs) # Older version
$fs.Close()
}
- Stefan HefeleOct 16, 2020Copper Contributor
AlyaKoni Works like a charm, thank you!
- DJ-11Jun 06, 2023Copper Contributor
AlyaKoni How could we also retrieve the CheckIn Comment for each version?
- AlyaKoniJun 06, 2023Copper ContributorFrom $version.CheckInComment
https://learn.microsoft.com/de-de/previous-versions/office/sharepoint-csom/ee539626(v=office.15)