Quantcast
Channel: SharePoint Diary
Viewing all articles
Browse latest Browse all 1058

Add-Remove Permissions to SharePoint Group or User with PowerShell

$
0
0
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 update user permissions using powershell in sharepoint 2016
  • Select or deselect any relevant permission levels required
    add remove permissions of a SharePoint group or user using powershell in sharepoint 2013
  • Click "OK" to save changes.

PowerShell script to update Permissions of a SharePoint group or User:
Here is my PowerShell script to change permission level of SharePoint group: Say, We want to remove "Edit" permission level and add "Contribute" to Members group of the SharePoint site.
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!"
}

#Remove Permission Level from the Group
if ($RoleAssignment.RoleDefinitionBindings.Contains($RemovePermissionRole))
{
$RoleAssignment.RoleDefinitionBindings.Remove($RemovePermissionRole)
Write-host "$($PermissionToRemove) permission removed from the Group!"
}

$RoleAssignment.Update()

Viewing all articles
Browse latest Browse all 1058

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>