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()
    }
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()
  • 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 :) – naijacoder Apr 30 '14 at 6:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.