May 22, 2019

SharePoint: Determining if library root level folders have broken permission inheritance using PnP PowerShell

This simple script can be used to determine status of permission inheritance of document library root level folders.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
$siteUrl = "https://mytenant.sharepoint.com/sites/somesitecollection"
Connect-PnPOnline -Url $siteUrl -UseWebLogin
$context = Get-PnPContext 

$list = Get-PnPList "SomeLibrary"

$folders = $list.RootFolder.Folders
$context.Load($folders)
$context.ExecuteQuery()

foreach($folder in $folders)
{
  if($folder.ItemCount -gt 0)
  {    
    $f = Get-PnPFolder -Url $folder.ServerRelativeUrl -Includes ListItemAllFields.RoleAssignments, ListItemAllFields.HasUniqueRoleAssignments

    $context.Load($f)
    $context.ExecuteQuery()

    Write-Host $f.ServerRelativeUrl -> $f.ListItemAllFields.HasUniqueRoleAssignments
  }
}

No comments:

Post a Comment