0

I'm banging my head against a wall trying to get this final piece written for an automatic SharePoint Online site collection script. The final piece is creating a list within the site collection (which I did), break inheritance on said list (which I did) and then remove all permissions from list (which I'm struggling with).

Look at the attached picture below. I don't need much explanation as I'm comfortable with PowerShell and CSOM, if someone has done this before I would appreciate a pointer.

I want to remove all of the permissions you see below, leaving the "1007 Owners" and "BTS 1007 Access Manager". All of the rest should be removed. Everything I've tried hasn't worked.

enter image description here

1

BreakRoleInheritance has two params. Just use false and true for copyroleassignments and clearsubscopes respectively then add the groups you want:

$list.BreakRoleInheritance($false,$true)
$group = $ctx.Web.EnsureUser($group)
$roleDef = $web.RoleDefinitions.GetByName($role)
$ctx.Load($group)
$ctx.Load($roleDef)
$roleBinding = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($ctx)
$roleBinding.Add($roleDef)
$ctx.Load($Web.RoleAssignments.Add($group, $roleBinding))
$ctx.executeQuery()
  • Thank you @Bunzab. This did it. For future people reading this, I needed to change: Line 2: $group = $ctx.Web.SiteGroups.GetByName($groupName) - was looking for a SP group permission, not a user Line 8: $ctx.Load($list.RoleAssignments.Add($group, $roleBinding)) - To populate the permissions on the list, not on the entire site collection. And of course populate the variables $groupName, $role and $list - $list = $ctx.Web.Lists.GetByTitle($ListTitle) – user2788110 Jul 6 '16 at 23:10
-2

Please check the following code

$web=Get-SPWeb http://site url
$list = $web.Lists["list/library name"]
[Microsoft.SharePoint.SPRoleAssignmentCollection] $spRoleAssignments=$list.RoleAssignments
for([int] $a=$spRoleAssignments.Count-1; $a -ge 0;$a--)
{
   if($spRoleAssignments[$a].Member.Name -eq "groupName")
   {
      $spRoleAssignments.Remove($a);
   }
}
  • The question states SharePoint Online, this is PowerShell only executing from the server itself – Robert Lindgren Jul 6 '16 at 8:53
  • Yes, that is for sharepoint on premise, SP online is pretty much all CSOM only. – user2788110 Jul 6 '16 at 20:14

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.