1
votes

How to get the column values of the items in a Sharepoint online document library using Powershell PNP? If all the document would have been in the root folder in the library, this works great.

Connect-PnPOnline –Url https://<company>.sharepoint.com/sites/<Site> –Credentials (Get-Credential)
$Item = Get-PnPListItem -List "SampleList" -Fields "Id","TestColumn"
$Item.FieldValues.TestColumn

However, I need to query the items in a subfolder that exists in "SampleList". And that seems to be harder.

Accodring to the documentation I can use -FolderServerRelativeUrl,

Get-PnPListItem -FolderServerRelativeUrl "/sites/<Site>/Lists/SampleList/Folder1"

But it cannot find the parameter -FolderServerRelativeUrl....

Get-PnPFolderItem : A parameter cannot be found that matches parameter name 'FolderServerRelativeUrl'

Any ideas of other cmdlets I can use?

2

2 Answers

1
votes

I soon realized that Get-PnPListItem returns all items, including folders and subfolders :) So I ended up using a Where-Object to filter the items instead.

$Item = Get-PnPListItem -List "SampleList" -Fields "Id","TestColumn" | Where-Object {$_.FieldValues.FileRef -like "*Folder1*"}
0
votes

I am able to call the mentioned cmdlet:

Get-PnPListItem -List Samples -FolderServerRelativeUrl "/sites/contosomarketing/Lists/Samples/Demo"

I tested it on my SP online environment:

Test:

enter image description here

So I suggest you have a check the value of 'FolderServerRelativeUrl' then have a try again.

BR