0

hope you can help me out. I'm working on a powershell script performing serveral modifications on a sharepoint environment.

I want to copy the RoleAssignments from on web to an other in the same site collection. Basicly it works when i run my commands manual in the console but it doesent work while running the script.

What I do is this.

    $RoleAssignmentMember =  $RoomWebRoleAssignment.Member
    $RoleBindings =  $RoomWebRoleAssignment.RoleDefinitionBindings
    $ctx.Load($RoleAssignmentMember)
    $ctx.Load($RoleBindings)
    $ctx.ExecuteQuery()


    $Web.RoleAssignments.Add($RoleAssignmentMember, $RoleBindings)
    $ctx.ExecuteQuery()

Running $Web.RoleAssignments.Add($RoleAssignmentMember, $RoleBindings) in console works.. not in the script .. I got an error that the collection is not ready .. but acutally it is^^..

Any Ideas ? Hope you can help Greetz

Constantin Treiber
  • 420
  • 1
  • 7
  • 18
  • Hi! can I ask you how are you getting $RoomWebRoleAssignment.Member and $RoomWebRoleAssignment.RoleDefinitionBindings from the first site? Thks! – mafalda Mar 09 '16 at 18:41
  • I load them via the context. Something like (SpWeb is a CSOM Object of a web) ctx.Load(spWeb, w=>w.RoleAssignments.Include( assignment => assignment.PrincipalId, ...... ) ) – Constantin Treiber Mar 10 '16 at 08:40

1 Answers1

0

Sorry, silly me.

for the people who are interested:

# Load it
$ctx.Load($Web.RoleAssignments.Add($RoleAssignmentMember, $RoleBindings));
$ctx.ExecuteQuery();
Alexey
  • 414
  • 3
  • 10
Constantin Treiber
  • 420
  • 1
  • 7
  • 18