0

I have a site collection with permissions set up as: EVERYONE READ I have a custom list. Here, I want to add permissions as EVERYONE CONTRIBUTE. I want to remove the Everyone Read Access Permssions but retain all other permissions like site members, owners, visitors etc to remain the same as that of site collection.

I am using this code to change the permssions(powershell and CSOM) :

$myList= $context.Web.Lists.GetByTitle(“Emp List”)
$myList.breakRoleInheritance($true, $false)
$everyone = $context.Web.EnsureUser("EveryOne") 
$everyoneRoleDef=$context.Web.RoleDefinitions.GetByName("Contribute")
$context.Load($everyoneRoleDef)
$roledefbingding_EveryOne=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection $context
$context.Load($roledefbingding_EveryOne)
$roledefbingding_EveryOne.Add($everyoneRoleDef)
$context.Load($myList.RoleAssignments.Add($everyone, $roledefbingding_EveryOne))
$myList.Update()
$context.ExecuteQuery()

The above code is perfectly working.

But it removes all other permissions for the list like: visitors, owners etc. - This is not expected. May be it happens because of the below line of code:

 $myList.breakRoleInheritance($true, $false)

I tried $myList.breakRoleInheritance($false, $true) But this will add permission as : EVERYONE READ,CONTRIBUTE - This is not expected.

This code adds "EVERYONE" as Contributors - This is expected.

DO I need to remove existing role ? If so please help me how to achieve this?

Thankyou

0

Try just deleting the Read role definition after adding the Contribute definition as follows:

$myList= $context.Web.Lists.GetByTitle(“Emp List”);
$myList.breakRoleInheritance($true, $false);
$everyone = $context.Web.EnsureUser("EveryOne");
$everyoneRoleDef=$context.Web.RoleDefinitions.GetByName("Contribute");
$everyoneReadRoleDef=$context.Web.RoleDefinitions.GetByName("Read");
$context.Load($everyoneRoleDef);
$roledefbingding_EveryOne=New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection $context;
$context.Load($roledefbingding_EveryOne);
$roledefbingding_EveryOne.Add($everyoneRoleDef);
$context.Load($myList.RoleAssignments.Add($everyone, $roledefbingding_EveryOne));
$context.Load($myList.RoleAssignments.GetByPrincipal($everyoneReadRoleDef).DeleteObject();
$myList.Update();
$context.ExecuteQuery();
-1

Your right breakRoleInheritance will break everything. Test it out in front end UI.

breakRoleInheritance : List will not inherit anything from sitecollection. You may need to add the remaining Groups in powershell again.

  • This answer doesn't add any value because it simply states the obvious that was already noted (more elaborately) in the question itself. – Cornelius J. van Dyk Sep 24 '18 at 21:11

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.