【发布时间】:2021-02-18 18:20:45
【问题描述】:
目前在 PnP.PowerShell 的 nightly 版本中,我们可以批量处理多个 PnP 请求(如下所述)。
$batch = New-PnPBatch
1..100 | ForEach-Object{ Add-PnPListItem -List "ItemTest" -Values @{"Title"="Test Item Batched $_"} -Batch $batch }
Invoke-PnPBatch -Batch $batch
但是,如果我需要从递归函数批处理命令,我们该如何执行呢? 我的要求是在文档库中获取文件夹和子文件夹。代码如下。
Function GetFolders($folderUrl)
{
$folderColl=Get-PnPFolderItem -FolderSiteRelativeUrl $folderUrl -ItemType Folder
# Loop through the folders
foreach($folder in $folderColl)
{
$newFolderURL= $folderUrl+"/"+$folder.Name
Write-Host $folder.Name " - " $newFolderURL
GetFolders($newFolderURL)
}
}
GetFolders($FolderPath)
如何让上面的代码使用 Batching
【问题讨论】:
标签: powershell recursion sharepoint-online batching