1

I want to remove the permission for each item and then want to add my unique permission I have tried the code for giving permission. But firstly, i want to remove it and then add new permission. My code is as below:

    $clientlist.Items | ForEach-Object{
                $clientlist.BreakRoleInheritance($True)
                $userNew = $webNew.EnsureUser($user)
                $roleDefinition = $webNew.RoleDefinitions[$PermissionLevel]
                $roleAssignment = New-Object Microsoft.SharePoint.SPRoleAssignment($userNew)
                $roleAssignment.RoleDefinitionBindings.Add($roleDefinition)
                $clientlist.RoleAssignments.Add($roleAssignment)
                $clientlist.Update()
                Write-Host "Successfully added $PermissionLevel permission to $UserNew in $clientlist list. " -foregroundcolor Green

}

Thanks.

1

To remove permissions for a given user:

    $clientlist.RoleAssignments.RemoveById($userOld.ID)

This will remove all permissions for a given user. You can use the same method on folders or list items.

0

Change $clientlist.BreakRoleInheritance($True) to $clientlist.BreakRoleInheritance($false) as $true in the argument of BreakRoleInheritance specifies that permissions from the parent be copied over to child. If you don't want any permissions from parent to be passed over user $false

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.