With Powershell CSOM and SharePoint 2013, I am trying to reset the permission to the domain group "Everyone", with the name "c:0(.s|true". Therefore I want to delete and recreate it, so that all the permissions "Everyone" has gotten over time have been reset.

What is the correct Powershell CSOM code for executing these actions?

I also want to do the same for the group "Everyone except external users", but I suspect it's the same procedure as to the question above.

EDIT: I'm also satisfied with a way to iterate through the permissions and removing them one by one. What is the Powershell CSOM command for removing a groups permission to a list?

EDIT2: I'll supply the code that I've currently built the last hour. I'm getting an error in the line:


Error: An error occurred while enumerating through a collection: The collection has no t been initialized. It has not been requested or the request has not been execu ted. It may need to be explicitly requested.


$permissions = $Context.Web.RoleDefinitions

$lists = $Context.Web.Lists

$group = $Context.Site.RootWeb.EnsureUser("c:o(.s|true")

foreach ($list in $lists)
    $list.BreakRoleInheritance($false, $true)
    foreach ($permission in $permissions){
         $roleAssignment = $null
         $roleAssignment = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Context)
  • I don't think you can recreate this group. You can go through and remove all role assignments that it has. – wjervis Jul 7 '15 at 13:27
  • I am satisfied with going through and removing all role assignments, but do you know how i do that? Can't seem to be able to find the "remove specific roleassignment from list" yet. – Coder1234 Jul 7 '15 at 13:38
  • I don't have much time to write up an answer, but the answer here should get you started. You can either use this link to convert the CSOM into PowerShell, or use this link to execute C# code from PowerShell (probably the simpler method). – wjervis Jul 7 '15 at 13:51
  • Just saw your edit. What is $group? Is it loaded? – wjervis Jul 7 '15 at 13:53
  • Yes. My code is all messy because of the ongoing edits, so I though I'd just say it was correctly initialized. $group = $Context.Site.RootWeb.EnsureUser("c:o(.s|true") – Coder1234 Jul 7 '15 at 13:56

Here's something to start with in C#:

$lists = $ctx.Web.Lists

foreach($list in $lists) {    
    $ras = $list.RoleAssignments
    foreach($ra in $ras) {        
        if ($ra.PrincipalId -eq $everoneUserId) {

That should do the job. It's been awhile since I've used PowerShell, so there might be some issues.

  • I tried converting to Powershell CSOM, but even though I have some experience in that field, I can't seem to accomplish the feat. Do you have any advice regarding the matter? – Coder1234 Jul 8 '15 at 6:54
  • @Coder1234 See update – wjervis Jul 8 '15 at 16:45
  • Thanks! I had to tweek the code since it does not accept deleting "$ra" while iterating "$ra in $ras". I inserted a "break" after "ctx.ExecuteQuery". Therefore it does not delete ALL permissions, but in my case, each group only have one permissionlevel for each list, so this is more than sufficient. Thanks again. – Coder1234 Jul 9 '15 at 9:04

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.