Forum Discussion
Paul Rudy
Oct 15, 2019Copper Contributor
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?
Actually, I found another way to get what I needed without using SharePoint. I was able to use the information at https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history to export the version history of the all of the files. I was then able to use Excel to end up with a list that had the metadata before the change and, finally, I used Sharegate to fix the metadata tags.
- Paul RudyCopper Contributor
Actually, I found another way to get what I needed without using SharePoint. I was able to use the information at https://sharepoint.stackexchange.com/questions/190021/exporting-item-list-version-history to export the version history of the all of the files. I was then able to use Excel to end up with a list that had the metadata before the change and, finally, I used Sharegate to fix the metadata tags.