PowerShell break inheritance on SharePoint Library and change permissions of Group

I had a requirement to change group members security group which has contribute permissions at the site collection to have read permissions to one document library.

The trick is to break inheritance on the document library and amend the role of the security group to Read.

$web =Get-SPWeb -Identity $webUrl
$docLibrary=$web.Lists.TryGetList($LibraryName)
$docLibrary.BreakRoleInheritance($False)
#get role definition from web: Full Control or Contribute or Read
$roleDefinitions = "Read"
#get site group
$siteGroup = $web.SiteGroups[$groupName]
#get the role assignment for the group
$roleAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($siteGroup)
$roleAssignment.RoleDefinitionBindings.RemoveAll();
$roleDefinition=$web.RoleDefinitions[$roleDefinitions];
$roleAssignment.RoleDefinitionBindings.Add($roleDefinition);
$docLibrary.RoleAssignments.Add($roleAssignment)
$docLibrary.Update();

The end result is to maintain contribute permissions at site collection

ContributePermissionAtSiteCollection

and read permissions at document library

ReadPermissionAtLibrary

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s