I want to break inheritance to a library and then remove members and visitors group. The code below works apart from the fact the library is still accessible but the content is not. The Quick launch also shows the link to the library, but no documents are visible. When I use the UI to break inheritance and remove the said groups, the library is not visible, so can't see why the code is not doing the same. Any ideas please?
# Break permissions inheritance for the library
$list.BreakRoleInheritance($true, $true)
$list.Update()
$list.Context.Load($list)
$list.Context.ExecuteQuery()
Write-Host -ForegroundColor GReen "Unique permissions set on library" $listTitle
# Remove Member and Visitor Groups
foreach ($y in $SiteGroups) {
#$MemberGroup = $title + " Members"
#$VisitorGroup = $Title + " Visitors"
if ($y.loginname -like "*Members") {
$SiteMembers = $y.loginname
Set-PnPGroupPermissions -Identity $SiteMembers -List $listTitle -RemoveRole "Contribute" -ErrorAction silentlycontinue
Write-Host -ForegroundColor Green "Member Group removed!"
}
If ($y.loginname -like "*Visitors") {
$SiteVisitors = $y.loginname
Set-PnPGroupPermissions -Identity $SiteVisitors -List $listTitle -RemoveRole "Read" -erroraction silentlycontinue
Write-Host -ForegroundColor Green "Visitor Group removed!"
}
}
UPDATE 1 - Not sure but might be related to limited access, and the code not being ale to clear these out. get a yellow box with warning when i view library permissions: 'There are limited access users on this site. Users may have limited access if an item or document under the site has been shared with them. Show users. This library has unique permissions.'