2

I am trying to remove permissions from a folder and then add new ones.

My script adds the permissions successfully but when I try and get rid of the permissions it inherited it's just not working, it just adds the new permissions on to it.

I am adding to a document library in Office 365

Write-Host "inheritance reset"
$item.ResetRoleInheritance()
$item.BreakRoleInheritance($true,$false)
$Context.Load($item)
$context.ExecuteQuery()
Write-host "Inheritance Broken"

$global:test =$true

if($isgroup -eq $true){
      $groups = $web.SiteGroups

      $context.Load($groups)

      $context.ExecuteQuery()

      $group = $groups | where {$_.Title -eq $groupAD}

}else{
      domainUser = $groups -replace '\\', '/'
      $fullUserName = ([adsi]"WinNT://$domainUser,user").fullname
      $groups = [string]$fullUserName
      if($groups -eq ''){
           $groups = "Rob Ireland"
      }
      $group = $Context.Web.EnsureUser($groups)
}

$collRdb = new-object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)                                
$collRdb.Add($roleDef)                                                             
$collRoleAssign = $item.RoleAssignments                               
$rollAssign = $collRoleAssign.Add($group, $collRdb)
$context.ExecuteQuery()
Write-host "$Permission have been added at $folderName for $groups"  
2

Try:

$item.BreakRoleInheritance($false,$false)

You will have to specify the first parameter as False, which means all the permissions from the parent will not be copied over. See the documentation for BreakRoleInheritance .

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.