简体   繁体   English

如何使用 PnP PowerShell 检索大型 SharePoint 库中的所有列表项

[英]How to retrieve all list items in a large SharePoint library using PnP PowerShell

I have a library that has about 25k items in it.我有一个图书馆,里面有大约 25,000 个项目。 I have a csv with a couple folders that I want to grant item level permission on.我有一个带有几个文件夹的 csv,我想授予项目级别的权限。 But first, to do that I need to retrieve all the items from the library.但首先,要做到这一点,我需要从库中检索所有项目。 As expected I get an error about threshold limit enforced by the administrator.正如预期的那样,我收到有关管理员强制执行的阈值限制的错误。 I was wander if there was a way to get around this with PnP.如果有办法通过 PnP 解决这个问题,我很困惑。

I basically used Get-PnPListItem -List Documents-PageSize 1000 to try an limit the number of items returned at once, but I still got the error message.我基本上使用Get-PnPListItem -List Documents-PageSize 1000来尝试限制一次返回的项目数,但我仍然收到错误消息。 I also tried the code below as well using a caml query;我还使用caml query;尝试了下面的代码caml query; that also didn't work.这也不起作用。

$filename = test.docx
Get-PnPListItem -List Documents -Query
"<View><Query><Where><Eq><FieldRef Name='FileLeafRef'/>
<Value Type='File'>' +$filename+ '</Value></Eq></Where></Query></View>"

I was only expecting one result to show, which is when the filename is found in the document library.我只希望显示一个结果,即在文档库中找到文件名时。 So I'm not sure why the error message is showing.所以我不确定为什么会显示错误消息。 Any ides?任何想法?

You can download the list into Excel.您可以将列表下载到 Excel 中。 In the List view, click Export to Excel .在列表视图中,单击导出到 Excel It will export all visible columns and all items.它将导出所有可见列和所有项目。 Then manipulate the Excel file and save as CSV.然后操作 Excel 文件并另存为 CSV。

Or, you can use Power Query to query the list and load it into Excel.或者,您可以使用 Power Query 查询列表并将其加载到 Excel 中。

Both approaches will support way more than 25K rows.这两种方法都将支持超过 25K 行。

This is a known issue.这是一个已知的问题。 If you want to retrieve some items from a large list (over 5000 items for SharePoint Online), there is no possible way to use the -Query parameter to Get-PnPListItem.如果要从大型列表(SharePoint Online 超过 5000 个项目)中检索某些项目,则无法使用 -Query 参数来获取-PnPListItem。 This is distressing because the main reason you're probably using -Query is that there are a lot of items and you want them filtered server-side to avoid excessive network bandwidth etc.这令人沮丧,因为您可能使用 -Query 的主要原因是有很多项目,并且您希望它们在服务器端过滤以避免过多的网络带宽等。

If you use -Query and also specify -PageSize, and/or put in the CAML query, it seems to have no effect and the server responds with "The attempted operation is prohibited because it exceeds the list view threshold enforced by the administrator".如果您使用 -Query 并指定 -PageSize,和/或放入 CAML 查询,它似乎没有效果,服务器响应“尝试的操作被禁止,因为它超出了管理员强制执行的列表视图阈值”。

The only workaround for this while still using PnP-PowerShell is to remove the -Query, get every item with -PageSize, then process the items locally with foreach/select/where-object.仍然使用 PnP-PowerShell 的唯一解决方法是删除 -Query,使用 -PageSize 获取每个项目,然后使用 foreach/select/where-object 在本地处理这些项目。 For more details, please refer to:欲知更多详情,请参阅:

Or you can have a try CSOM cmdlets and add the filtered column into indexs list:或者您可以尝试 CSOM cmdlet 并将过滤后的列添加到索引列表中:

BR BR

This does work with the pnp.powershell module to get more rows out then 5000.这确实适用于 pnp.powershell 模块,以获得比 5000 多的行。

$query = "<View Scope='RecursiveAll'><RowLimit>5000</RowLimit></View>" 
$itemsInList = Get-PnPListItem -List 'TestList' -Query $query

Its not supposed to work like that.它不应该像那样工作。

If you need to query on large lists, be sure to add Indexes for the field(s) you are querying.如果您需要对大型列表进行查询,请确保为您正在查询的字段添加索引。

But this will still NOT make your query limited by -PageSize or the RowLimit tag in your query using PnP-Powershell.但这仍然不会使您的查询受到使用 PnP-Powershell 的查询中的 -PageSize 或 RowLimit 标记的限制。

You will need to use the -Scriptblock option to process items in batches.您将需要使用 -Scriptblock 选项来批量处理项目。

对于 SPO PNP.PowerShell实际上只需要使用-PageSize 5000

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PnP powershell 更改共享点列表项 - PnP powershell change sharepoint list items Sharepoint PnP 列表:如何使用 Powershell“分组依据”列 - Sharepoint PnP List: How to “Group by” columns using Powershell 使用 Powershell PNP 获取 Sharepoint 在线文档库中特定文件夹中的项目 - Get items in specific folder in Sharepoint online document library with Powershell PNP 获取 SharePoint 列表项中的附件文件大小 - PnP Powershell - Get the attachment file size in SharePoint list items - PnP Powershell 如何使用 PnP Powershell 删除所有列表项权限 - How to remove all list item permissions using PnP Powershell 使用 powershell 更新 Sharepoint 所有列表项 - Update Sharepoint All list items using powershell 使用 pnp 更新 SharePoint 在线文档库列属性 PowerShell - update SharePoint online document library column property using pnp PowerShell 使用PnP PowerShell for SharePoint Online在文档库上设置“说明” - Setting the “Description” on a Document Library using PnP PowerShell for SharePoint Online 如何使用 pnp powershell 获取 SharePoint 在线列表中最后修改项目的项目 ID? - How to get item ID of the last modified item in the SharePoint online list using pnp powershell? 在SharePoint中使用PowerShell从文档库中获取项目列表 - Getting a list of items from document library using PowerShell in SharePoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM