magritton
1/15/2016 - 7:10 PM

This goes through all of the sub sites in a site and adds groups sets the permissions for the groups. Good example of breaking or resetting

This goes through all of the sub sites in a site and adds groups sets the permissions for the groups. Good example of breaking or resetting Role inheritance, adding groups and calling functions in powershell.

Add-PsSnapin Microsoft.SharePoint.PowerShell

function setPermissions($NewGroup,$PermissionLevel,$web)
{
    #Assign Permissions to the Group
    $group = $web.SiteGroups[$NewGroup]
    $GroupAssignment = new-object Microsoft.SharePoint.SPRoleAssignment($group)

    #Get Full Control Role (Permission Level)
    $GroupRoleDefinition = $web.Site.RootWeb.RoleDefinitions[$PermissionLevel]
     
        #Bind Full Control
    $GroupAssignment.RoleDefinitionBindings.Add($GroupRoleDefinition)
 
    #Grant Full control to the Web
    $web.RoleAssignments.Add($GroupAssignment)

}

$topSite = Get-SPWeb http://scushp01/Branches
foreach($s in $topSite.Webs)
{
    ##$s.Update()
    ##$s.ResetRoleInheritance()
    
    ##$s.BreakRoleInheritance($False)
    ##$s.Update()
	$s.Title
	
    $NewMembers = $s.Title + " Members"
    $NewVisitors = $s.Title + " Visitors"
    $NewEditors = $s.Title + " Editors"
    $NewDesigners = $s.Title + " Designers"
    $NewOwners = "TheSound Owners"
    
    setPermissions $NewMembers "Contribute" $s
    setPermissions $NewVisitors "Read" $s 
    setPermissions $NewEditors "Edit" $s 
    setPermissions $NewDesigners "Design" $s
    setPermissions $NewOwners "Full Control" $s

}