I am trying to modify the permission level of SharePoint groups and users with direct permission using PowerShell, e.g. if group/user has been given full control, I need to modify it to read.
I have created a script which will remove that groups permission and add it again with read access. But, the issue here is that when I remove the group from site collection, it gets removed from all libraries also. So, for workaround I'm storing the group names in an array and again adding them to each library.
Is it possible to just modify the permission level of a SharePoint group and users with direct permission using PowerShell?
code:
for($i = 0; $i -lt $WebRoleAssignments.Count; $i++){
$WebRoleAssignment = $web.RoleAssignments[$i]
$Member = $WebRoleAssignment.Member
$web.RoleAssignments.Remove($Member)
Write-Host Default Permissions Removed for $Member
$assignment = new-object Microsoft.SharePoint.SPRoleAssignment($Member)
$permission = $web.RoleDefinitions["Read"]
$assignment.RoleDefinitionBindings.Add($permission)
$web.RoleAssignments.Add($assignment)
Write-Host Read access granted for $Member
$groups += $Member
}