Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am doing the following using powershell.

I am creating a site collection with 4 subsites and 5 custom groups.

Site Collection : Parent Child Site : One Child Site : Two Child Site : Three

There are four groups :

Group A, B, C, D

Access for the sites is as follows :

Child Site One : Group A, B, C, D (All groups have approve access) Child Site Two : Group A, B, D (All groups have approve access) Child Site Three : Group A, B, C (All groups have approve access)

I am creating all this in a powershell script.

How do I set the groups permission in a powershell script for the sitecollection and subsite? I understand that on the front end I can select the group within the site and break inheritance and then "Remove the Permissions" and this removes the group from the child site. How do I do this in powershell as this needs to be scripted.

PS Child Site Three/ Two each have a group that have no access.

share|improve this question
add comment

1 Answer

To break inheritance on a site and give permissions to the groups you can use this code:

$web.BreakRoleInheritance($false)

$roleDefinition = $web.Site.RootWeb.RoleDefinitions["Approve"]

$groupAssignmentA = new-object Microsoft.SharePoint.SPRoleAssignment($groupA)
$groupAssignmentA.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add(groupAssignmentA)

$groupAssignmentB = new-object Microsoft.SharePoint.SPRoleAssignment($groupB)
$groupAssignmentB.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add(groupAssignmentB)

$groupAssignmentC = new-object Microsoft.SharePoint.SPRoleAssignment($groupC)
$groupAssignmentC.RoleDefinitionBindings.Add($roleDefinition)
$web.RoleAssignments.Add(groupAssignmentC)

$web.Update();

Where $web is the subsite you want to give the permissions and $groupA, $groupB and $groupC an instance of the corresponding SPGroup.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.