递归函数中的批处理 PnP PowerShell 命令

问题描述

目前在 PnP.PowerShell 的夜间版本中,我们可以批量处理多个 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)

如何让上面的代码使用批处理

解决方法

根据文档:https://pnp.github.io/powershell/articles/batching.html

Get-PnPFolderItem cmd 不支持批处理。

enter image description here