Forum Discussion

Paul Rudy's avatar
Paul Rudy
Copper Contributor
Oct 15, 2019
Solved

Using SharePoint PNP to get item properties on older version

So I made a mistake and overwrote one column of metadata (Donor_Name) in a SharePoint library using a 3rd party tool (my mistake not the tool). I can see that the older versions of the documents still have the correct metadata so I would like to grab the metadata from the first versions of these documents which I can then use to fix the documents. I have the code below which lets me retrieve the versions. What I want is something like $file[0] that lets me retrieve the file name and Donor_Name and export it to a CSV?

Is this possible? Otherwise I will need to find some other way to retrieve the data?

 

 

$site = '<My Site>'
$Library = '<Libray>'

Connect-PnPOnline -Url $site -Credentials <save creds>
$grants = get-pnplist -Identity $Library
$ctx = Get-PnPContext
$documents =Get-PnPListItem -List $grants

$versions 
foreach ($item in $documents)
{
        $file = $item.file
        $fileversions = $file.Versions
        $ctx.load($file)
        $ctx.load($fileversions)
        $ctx.ExecuteQuery()
        
}

 

 

 Any ideas are welcome? 

Resources