Forum Discussion
Joe DeNicola
Mar 08, 2018Copper Contributor
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...
- Mar 12, 2018
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!
paulpascha
Mar 12, 2018Bronze 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!
- Rohit404404Apr 02, 2024Brass Contributor
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 DeNicolaMar 12, 2018Copper 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 }