1

We have a SharePoint which uses claims based authentication. I need to iterate through all files in library using PowerShell and share the each with a particular claim.

Could you please help me to to figure our how can I add a claim as a user/group in PowerShell considering the following scripts:

Add-PSSnapin Microsoft.SharePoint.PowerShell 
$url = "http://mysite"
$listName = "mylist"
$permissionLevel = "read"
$groupName = "c:0-.f|rolesprovider|claim"
$web = Get-SPWeb $url
$list = $web.Lists[$listName]
$group = $web.EnsureUser($groupName) #Exception calling "EnsureUser" with "1" argument(s): "The specified user could not be found."
$role = $web.RoleDefinitions[$permissionLevel]
$assignment = New-Object Microsoft.SharePoint.SPRoleAssignment($group)
$assignment.RoleDefinitionBindings.Add($role)
foreach ($item in $list.Items) {
        $item.RoleAssignments.Add($assignment)
        $item.Update()
    }
}
$web.Dispose();
1

See Programmatically granting permissions to claims

  • The article is useful, but the question was about how to do this with PowerShell... Can you improve your answer adding a relevant code sample? It will also be better than just referencing external site. – arax28 Oct 17 '17 at 13:11

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.