2012-10-04 2 views
1

나는 Sharepoint 2010 최상위 사이트를 Test라는 이름으로두고 있습니다. test 아래에는 각각 test1, test2, test3이라는 세 개의 하위가 있습니다. 최상위 사이트 (Test)에는 test1group, test2group 및 test3group의 세 가지 사용자 정의 그룹 이름이 있습니다.PowerShell 스크립트에서 도움이 필요합니다.

powershell 스크립트를 사용하여 그룹 및 권한을 해당 하위 사이트로 내보내려고합니다. 예를 들어, 우리가 그룹 및 허가를 내보낼 경우 test1 하위 사이트 다음 test1group 만 test2group 및 test3group .. 및 test2 그룹에 대한 그룹 내보내기를 수행하는 similary 상속해야합니다 test2group inheriated해야합니다 ... not 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() 
} 

그러나 매번 자사의 최상위 사이트에서 모든 그룹을 inhereting을 (이 기본 동작입니다.) .... 위의 기능을 수행 할 수 있도록 powershell 스크립트를 사용자 정의 할 수 있습니까? 모든 도움을 주시면 감사하겠습니다.

답변

0

상속을 해제하면 원래 상속 된 내용의 복사본이 만들어집니다.

은 내가 셰어 편리한 명령이없는,하지만 당신은 처음에 상속 그룹을 제거하는

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

안녕하세요 스티븐과 같이 할 수 :) ... 나의 이해에 따라 당신의 reply..but에 대한 감사 이것은 단지 하나를 제거합니다 group..I을 모든 그룹을 삭제해야하는 다른 그룹을 유지하고 싶습니다. – user1133737

+0

맞습니다. 이렇게하면 하나의 그룹이 삭제되므로 각 사이트에서 제거하려는 그룹마다 한 번씩 실행해야합니다. –

관련 문제