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:
$list.RoleAssignments.Remove($group,$roleAssignment)
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.
Code:
$permissions = $Context.Web.RoleDefinitions
$Context.Load($permissions)
$Context.ExecuteQuery()
$lists = $Context.Web.Lists
$Context.Load($lists)
$Context.ExecuteQuery()
$group = $Context.Site.RootWeb.EnsureUser("c:o(.s|true")
$Context.Load($group)
$Context.ExecuteQuery()
foreach ($list in $lists)
{
$list.BreakRoleInheritance($false, $true)
foreach ($permission in $permissions){
$roleAssignment = $null
$roleAssignment = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($Context)
$roleAssignment.Add($permission)
$list.RoleAssignments.Remove($group,$roleAssignment)
$Context.ExecuteQuery()
}
}