SOLVED

Getting a file's metadata field values using Pnp

Copper Contributor

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?

 

3 Replies
best response confirmed by Joe DeNicola (Copper Contributor)
Solution

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!

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 }

@Paul Pascha 

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.

1 best response

Accepted Solutions
best response confirmed by Joe DeNicola (Copper Contributor)
Solution

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!

View solution in original post