Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: PowerShell
Hi all,
 
I have sharepoint 2010 toplevel site with name Test. Under test there are three subsites with name test1, test2, test3 respectively. In top level site (Test) there are three custom group names are: test1group, test2group and test3group.
 
Using powershell script I want to export the group and permission to their respective subsite. For example if we want to export the group and permission in test1 subsite
then only test1group should be inherited not test2group and test3group..and the similary while performing group export for test2 subsite then, only test2group should be inheriated...not test1group and test2group....and so on(for test3 subsite)..
 
Using the below scripts I was trying to perform this:
 
function AddGroupToSite($url, $groupName, $permLevel)
    {
    $web = Get-SPWeb $url
    #Break permissions inheritance and copy the groups from parent site into this site     (recommended)
 
     $web.BreakRoleInheritance($true)
     $web.Update()
    #Creating a new group:
    $web.SiteGroups.Add($groupName, $web.Site.Owner, $web.Site.Owner, "New Group from   powershell 4")
     $newGroup = $web.SiteGroups[$groupName]
 
    #Create role assignment:
    $newGroupAssign = New-Object Microsoft.SharePoint.SPRoleAssignment($newGroup)
 
    #Assign a specific role
    #The possible enumeration values are: None, Guest, Reader, Contributor, WebDesigner, Administrator
    $newGroupAssign.RoleDefinitionBindings.Add($web.RoleDefinitions.GetByType($permLevel))
    $web.RoleAssignments.Add($newGroupAssign)
 
    #Update web
    $web.Update()
    $web.Dispose()
    }
But everytime its inhereting all the group from top level site(which is default behavior)....Can we customize the powershell script so that we can achieve the above functionality..Any help is highly appreciated.
Posted 4-Oct-12 6:25am
Rahul48537
Edited 4-Oct-12 7:34am
(no name)105.2K
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 4 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100