kwizcom banner advertisement

Add-Remove Permissions to SharePoint Group or User with PowerShell

Updating the permission level of a SharePoint group or user is fairly straightforward. To add or remove permissions levels of the SharePoint group, Navigate to:
  • Site Settings >> Site permissions
  • Select the person or group you want to change >> Click on "Edit User Permissions" ribbon button sharepoint powershell change group permissions
  • Select or deselect any relevant permission levels required
    sharepoint powershell add remove group permissions
  • Click "OK" to save changes.

PowerShell script to update Permissions of a SharePoint group or User:
Here is my PowerShell script to change permissions of a SharePoint group: Say, We want to remove "Edit" permission level and add "Contribute" to Members group of the SharePoint site.
#assign permission to sharepoint group powershell
Add-PSSnapin "Microsoft.SharePoint.PowerShell" -ErrorAction SilentlyContinue

#Configuration parameters
$SiteURL="http://intranet.crescent.com"
$GroupName="Crescent Intranet Members"
$PermissionToAdd="Contribute"
$PermissionToRemove="Edit"

#Get the Web & Group objects
$Web = Get-SPWeb $SiteURL
$Group = $web.SiteGroups[$GroupName]
$RoleAssignment = $Web.RoleAssignments.GetAssignmentByPrincipal($Group)

#For User, Use:
#$User = $web.EnsureUser("Crescent\Salaudeen")
#$RoleAssignment = $Web.RoleAssignments.GetAssignmentByPrincipal($User)

#Get the permission Levels to Add - Remove
$AddPermissionRole = $web.RoleDefinitions[$PermissionToAdd]
$RemovePermissionRole = $web.RoleDefinitions[$PermissionToRemove]

#Add Permission level to the group
if (!$RoleAssignment.RoleDefinitionBindings.Contains($AddPermissionRole))
{
    $RoleAssignment.RoleDefinitionBindings.Add($AddPermissionRole)
    Write-host "$($PermissionToAdd) Permission Added to the Group!"
}

#sharepoint powershell remove group permissions
if ($RoleAssignment.RoleDefinitionBindings.Contains($RemovePermissionRole))
{
    $RoleAssignment.RoleDefinitionBindings.Remove($RemovePermissionRole)
    Write-host "$($PermissionToRemove) permission removed from the Group!"
}
 
$RoleAssignment.Update()
Add-Remove Permissions to SharePoint Group or User with PowerShell Add-Remove Permissions to SharePoint Group or User with PowerShell Reviewed by Salaudeen Rajack on July 04, 2016 Rating: 5

No comments:

Please Login and comment to get your questions answered!

Powered by Blogger.