简体   繁体   中英

Get items in specific folder in Sharepoint online document library with Powershell PNP

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?

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*"}

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:

在此处输入图像描述

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

BR

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM