简体   繁体   English

在Powershell脚本中需要帮助。

[英]Need help in powershell script.

I have sharepoint 2010 toplevel site with name Test. 我有一个名为Test的sharepoint 2010顶级站点。 Under test there are three subsites with name test1, test2, test3 respectively. 在测试中,有三个子站点,分别名为test1,test2,test3。 In top level site (Test) there are three custom group names are: test1group, test2group and test3group. 在顶级站点(测试)中,有三个自定义组名称:test1group,test2group和test3group。

Using powershell script I want to export the group and permission to their respective subsite. 使用powershell脚本,我想将组和权限导出到它们各自的子站点。 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).. 例如,如果我们要在test1子站点中导出组和权限,则仅继承test1group而不继承test2group和test3group ..并且在对test2子站点执行组导出时类似,则仅继承test2group ...不继承test1group和test2group ....依此类推(用于test3子站点)。

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. 但是每次它都会从顶级站点插入所有组(这是默认行为)。...我们可以自定义powershell脚本,以便实现上述功能。.非常感谢您的帮助。

When you break the inheritance, it creates a copy of what was originally inherited. 中断继承时,它将创建原始继承的副本。

I don't have the Sharepoint commands handy, but you should be able to do something like 我没有Sharepoint命令,但是您应该可以执行以下操作

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

to remove the initially inherited groups. 删除最初继承的组。

So you could add this to your existing script and have something like 因此,您可以将其添加到现有脚本中,

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM