Mar 08 2018 02:25 PM - edited Mar 08 2018 02:26 PM
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?
Mar 12 2018 01:53 AM
SolutionI'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!
Mar 12 2018 01:44 PM - edited Mar 12 2018 01:45 PM
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 }
Apr 02 2024 10:56 AM
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.
Mar 12 2018 01:53 AM
SolutionI'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!