I try to set specific permission on list items. I found some examples but I'm working in Powershell and I get a strange error
The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
Here's my code:
foreach($item in $collListItem) { $srcContext.Load($item) $srcContext.ExecuteQuery() $item.BreakRoleInheritance($false, $false); $RoleDefBind = New-Object Microsoft.SharePoint.Client.RoleDefinitionBindingCollection($srcContext) $PermissionLevel = $srcContext.Web.RoleDefinitions.GetByName("Lecture") #userToAdd $user = $srcWeb.SiteUsers.GetByLoginName("i:0#.w|domain\test"); $srcContext.Load($user) $srcContext.ExecuteQuery() $RoleDefBind.Add($PermissionLevel) $Assignments = $item.RoleAssignments $srcContext.Load($Assignments) $srcContext.ExecuteQuery() $item.Update() $srcContext.ExecuteQuery() $Assignments.Add($user,$RoleDefBind) $srcContext.Load($Assignments) $srcContext.ExecuteQuery() } The error is always on the line $Assignments.Add($user,$RoleDefBind)
I added a lot of Load and ExecuteQuery... I can debug and see that Assignments exists, same for user and RoleDefBind.
I really don't understand what's missing. Please help.
Thanks