1

I am trying to break permission inheritance for certain folders in my document library in office 365. However when $folder.BreakRoleInheritance($false) is executed I get an error:

Method invocation failed because [Microsoft.sharepoint.client.folder] does not contain a method named breakroleinheritance

my code:

function GetChildFolders($RootFolder) 
{
    if($count -ne 1){
        $folderName=$folderName+'\\'+$RootFolder.Name
    }
    $Context.Load($RootFolder)
    $Context.Load($RootFolder.Folders)

    $Context.ExecuteQuery()

    $count++

    if($folderName -eq $FolderRelativePath){                                
        $RootFolder.BreakRoleInheritance($true,$false)
        Write-host "Inheritance Broken"
        $group = $Context.web.SiteGroups[$groupAD];   
        write-host "group added"
        $collRdb = new-object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($context)

        $collRdb.Add($permission)
        Write-host "Permission added"
        $collRoleAssign = $RootFolder.Item.RoleAssignments

        $rollAssign = $collRoleAssign.Add($group, $collRdb)

        $context.ExecuteQuery()
    }

    foreach($folder in $RootFolder.Folders)
    {
        GetChildFolders $folder                       
    }
}
GetChildFolders $List.RootFolder
2

Microsoft.sharepoint.client.folder does not have property for "BreakRoleInheritance"

You can use as below to break permission inheritance

$RootFolder.ListItemAllFields.BreakRoleInheritance($true,$false)

Hope it will help to you.

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.