1

我有名为 Test 的 sharepoint 2010 顶级站点。在测试中有三个子站点,分别名为 test1、test2、test3。在顶级站点(测试)中有三个自定义组名称是:test1group、test2group 和 test3group。

使用 powershell 脚本,我想将组和权限导出到各自的子站点。例如,如果我们要导出 test1 子站点中的组和权限,那么应该只继承 test1group,而不是 test2group 和 test3group.. 并且在为 test2 子站点执行组导出时类似,应该只继承 test2group...而不是 test1group 和 test2group ....等等(对于 test3 子站点)..

使用以下脚本我试图执行此操作:

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()
}

但是每次它从顶级站点继承所有组(这是默认行为)....我们可以自定义powershell脚本以便我们可以实现上述功能..任何帮助都非常感谢。

4

1 回答 1

0

当您中断继承时,它会创建最初继承的副本。

我没有方便的 Sharepoint 命令,但你应该能够做类似的事情

function Remove-SPGroup ($url, $groupName)
{
  $web = Get-SPWeb $url
  $web.SiteGroups.Remove($GroupName)
  $web.Update()
  $web.dispose()
}

删除最初继承的组。

所以你可以把它添加到你现有的脚本中,并有类似的东西

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]

 foreach ($ExistingGroup in $web.SiteGroups)
 {
   if ($ExistingGroup.name -notlike $groupname)
   {
     $web.SiteGroups.Remove($ExistingGroup.name)
    }
  }

#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()
}
于 2012-10-04T15:39:22.167 回答