Forum Discussion

Joe DeNicola's avatar
Joe DeNicola
Copper Contributor
Mar 08, 2018
Solved

Getting a file's metadata field values using Pnp

Using Powershell Pnp and SharePoint Online, I want to get the values in the custom fields of a file. I do not want to download the file, I just need the custom (metadata) fields.

 

For example, I have a custom field in a document library "Customer ID" and a file in that library named "CustomerFile.xlsx".

 

If I try Get-PnpFolderItem, it gives me back a few standard attributes (Name, Type, Size, Last Modified), but none of the custom fields.

 

If I try Get-PnpFile with the -Url and -AsListItem, it gives me back the ID, Title, and GUID only.

 

Is there a way to use Pnp to get the value of "Customer ID" (i.e. Customer_x0020_ID) for a given file that I know exists?

 

  • I've just did a quick test. The following gives me the expected value from a custom column in one of my files:

     

    PS C:\Users\Paul> Connect-PnPOnline https://mytenant.sharepoint.com/sites/test -Credentials $credentials
    PS C:\Users\Paul> $f = Get-PnPFile -Url "/sites/test/Library/Document.pdf" -AsListItem
    PS C:\Users\Paul> $f["CustomField"]
    Custom Field Value

     

    Hope this helps!

3 Replies

  • paulpascha's avatar
    paulpascha
    Bronze Contributor

    I've just did a quick test. The following gives me the expected value from a custom column in one of my files:

     

    PS C:\Users\Paul> Connect-PnPOnline https://mytenant.sharepoint.com/sites/test -Credentials $credentials
    PS C:\Users\Paul> $f = Get-PnPFile -Url "/sites/test/Library/Document.pdf" -AsListItem
    PS C:\Users\Paul> $f["CustomField"]
    Custom Field Value

     

    Hope this helps!

    • Rohit404404's avatar
      Rohit404404
      Brass Contributor

      paulpascha 

      Any equivalent for folder? 

       

      We have large library and only folder URLs/Paths. We are looking to update the metadata. However, there is no "-AsListITem" equivalent for folder it seems.

    • Joe DeNicola's avatar
      Joe DeNicola
      Copper Contributor

      Thanks, that's similar (but simpler) than the method I eventually came up with.

      Since I am pulling in documents from a CAML query, I did this:

       

      (Get-PnpListItem -List "My Documents" -Query $docsQuery).FieldValues | Foreach-Object -Process {
          $docFilename = $_.FileLeafRef
      $customerID = $_.Customer_x0020_ID }

Resources