1

I have tried using the below to add specific user to items but it keep getting error. For now I'm just trying to add permission to specific item but I would be changing the code to look at a column of a people picker type with multiple users.

I would appreciate if someone can tell me what I'm doing wrong

Exception calling "Add" with "1" argument(s): "" At +
$CMRSItems.RoleAssignments.Add($assignment)

$web.AllowUnsafeUpdates = $true
$user = $web.EnsureUser("domain\username")

$role = $web.RoleDefinitions["Read"]
$CMRSItems = $list.Items | where {$_['ID'] -eq 2}


$CMRSItems | ForEach-Object {

    Write-Host "ItemID: " $_['ID']
    $assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($user)
    $assignment.RoleDefinitionBindings.Add($role)
    #$web.RoleAssignments.Add($assignment);
    $CMRSItems.RoleAssignments.Add($assignment)
    $CMRSItems.Update()
    $web.Dispose()
    }

1 Answer 1

2

Isn't this part

$CMRSItems.RoleAssignments.Add($assignment)
$CMRSItems.Update()

modifying the collection of items rather than the current item?

Try something like

$_.RoleAssignments.Add($assignment)
$_.Update()
1
  • Thanks Rob.Got it rolling i was using i:0#.w|domainname\username and i had to format it to use domainname\username.It seems thats what webensurer needed :) Commented Apr 30, 2014 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.