Forum Discussion

Brent Ellis's avatar
Brent Ellis
Silver Contributor
Oct 21, 2016

a way to retrieve metadata of a previous version of a file? (using CSOM in PowerShell in SPO)

I am using CSOM in PowerShell, querying SharePoint Online, but in general, I am looking for a way to retrieve what a specific column/value was on previous versions of a document programmatically.

 

I can get to the actual previous versions this way, and some basic version values, like url, created date, etc, but can't seem to find anything about the actual custom column values.

 

$Versions = $item.File.Versions
$clientContext.Load($Versions)
$clientContext.ExecuteQuery()

foreach($Version in $Versions){
   Write-Host $Version.VersionLabel
   Write-Host $Version.Url
   Write-Host $Version.Created
}

9 Replies

  • Hi Brent Ellis, have a look at the https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-august-2017 release, especially those classes:

    • public property Microsoft.SharePoint.Client.ListItem.Versions
    • public class Microsoft.SharePoint.Client.ListItemVersion
    • public class Microsoft.SharePoint.Client.ListItemVersionCollection

     

    I  have not seen what is in these classes yet, if they do not work for you then you can assess the List Item Version Metatdata item from the _vti_bin/Lists.asmx service. More info here: http://blog.velingeorgiev.pro/how-get-list-item-field-versions-data-sharepoint-online. It is not ideal solution ad would be great if the august update offers that, but it is the only alternative I found so far.

    • Jim Duncan's avatar
      Jim Duncan
      Iron Contributor

      Velin Georgiev That last link now takes the user to a malware site. I know this post is from 5 years ago, but still...

    • Brent Ellis's avatar
      Brent Ellis
      Silver Contributor
      Appreciate all the responses, I managed to figure it out a while back (but didn't update this thread), but I believe I used this CSOM route you referenced to do it.
      • Dinesh Natarajan's avatar
        Dinesh Natarajan
        Copper Contributor

        Hi Brent,

         

        Can you pls share your solution which you implemented. Thanks!

         

        Dinesh

  • Brent Ellis have a look at this update https://dev.office.com/blogs/new-sharepoint-csom-version-released-for-Office-365-august-2017 and especially those classes:

     

    public property Microsoft.SharePoint.Client.ListItem.Versions

    public class Microsoft.SharePoint.Client.ListItemVersion

    public class Microsoft.SharePoint.Client.ListItemVersionCollection

     

    If they do not work for you, there is a way to do it from the _vti_bin/Lists.asmx service.

    More info here: http://blog.velingeorgiev.pro/how-get-list-item-field-versions-data-sharepoint-online. It is not first class solution, but getting version metadata was not available in CSOM few months ago, I do know know if the august 2017 update will offer more on versions metadata (haven't tested it yet). Let me know if works, thanks!

    • Jim Duncan's avatar
      Jim Duncan
      Iron Contributor

      That last link now takes the user to a malware site. I know this post is from 5 years ago, but still...

Resources