Harsh Jaswal
Harsh Jaswal

Reputation: 447

Give edit permission to "Everyone" in SharePoint list using PowerShell Client side code

I have created a list in SharePoint site using PowerShell client side code. Now I want to edit the permission for this list. I want to give edit permission for this list to Everyone. This is how I am getting the Everyone detail:

$Ctx = New-Object Microsoft.SharePoint.Client.ClientContext($SiteURL)
$user  =$Ctx.web.EnsureUser("c:0(.s|true")
$Ctx.Load($user)
$Ctx.ExecuteQuery()

And to break the inheritance of the list I used this:

$List = $Ctx.Web.Lists.GetByTitle("ListName")
$Ctx.Load($List)
$Ctx.ExecuteQuery()
$List.BreakRoleInheritance($true)

But I am not sure how to give edit permission for this list to Everyone. Any suggestion would be helpful. Thanks

Upvotes: 0

Views: 664

Answers (1)

Vadim Gremyachev
Vadim Gremyachev

Reputation: 59358

Here is a sample on how to grant Edit permissions to principal per List:

$roleDefinition = $ctx.Site.RootWeb.RoleDefinitions.GetByType([Microsoft.SharePoint.Client.RoleType]::Editor)  
$roleBindings = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($ctx) 
$roleBindings.Add($roleDefinition)
$ctx.Load($list.RoleAssignments.Add($user, $roleBindings))
$ctx.ExecuteQuery()

Prerequisites

SharePoint Online Client Components SDK

Upvotes: 1

Related Questions