如何使用 Get-PnPFolder 显示 SharePoint 文件夹 perm

How to use Get-PnPFolder to show SharePoint folder perm

我正在使用 PowerShell PNP 尝试读取文件夹的权限,但命令 Get-PnPFolder 似乎不包含权限。

我尝试了此处列出的代码,但权限集合为空。 https://sharepoint.stackexchange.com/questions/221118/retrieve-permissions-at-folder-and-file-level-in-powershell/221513。下面这个小样本是我用来测试的。

$spserver = 'https://myportal.sharepoint.com/sites/mysite/'
Connect-PnPOnline –Url $spserver –UseWebLogin
$foldername = 'myFormLibraryName'
$folderObj = Get-PnPFolder -Url $foldername -Includes ListItemAllFields.RoleAssignments, ListItemAllFields.HasUniqueRoleAssignments 
$folderObj.ListItemAllFields.HasUniqueRoleAssignments
$folderObj.ListItemAllFields.RoleAssignments

代码的结果将return“collection has not been initialized”。如何获取 SharePoint 文件夹的权限列表?

我无法让代码与 Get-PnPFolder 一起使用,因此使用下面的代码作为替代。

$spserver = 'https://myportal.sharepoint.com/sites/mysite/'
Connect-PnPOnline –Url $spserver –UseWebLogin
$ctx=Get-PnPContext
$foldername = 'Documents'
$web = $ctx.Web
$list = $ctx.Site.RootWeb.Lists.GetByTitle($foldername)
$ctx.Load($list)
$ctx.ExecuteQuery()
Write-Host 'count is ' $list.ItemCount
$roleass = $list.RoleAssignments
$ctx.Load($roleass)
$ctx.ExecuteQuery()
Write-Host 'loaded'
foreach($rol in $roleass) {
    $ctx.Load($rol.Member)
    $ctx.ExecuteQuery()
    Write-Host $rol.Member.Title
}