2012-04-05 4 views
0

동일한 실행에서 $ouUnixGroups 개체를 만들 때 작동하는 GrantGenericRead 함수가 있습니다. 내가 밖으로 실행할 수있는 광고 밖으로 개체를 얻을 방법을 알아 내려고 노력하고있어 GrantGenericRead,하지만이 모든 방법을 시도 할 때 보인다 (adsi, 조회를 사용하여. 경로), 나는 일부 속성에 액세스 할 수 없습니다 그것을 설정하는 객체의 나는 누군가가 내가 뭘 잘못하고 있는지 말해주는 걸 좋아할거야. 내가 달성하기 위해 노력하고있어Active Directory의 Powershell 액세스 목록

function CreateADGroup([string] $server, [string] $name, [string] $container, [string] $gtype) 
{ 
    $objClass = "group"; 
    $strCn = GetCn -name $name -objClass $objClass; 
    $objDsGroup = CreateDsObject -server $server -container $container -name $name -objClass $objClass 
    [Void] $objDsGroup.Put("sAMAccountName", $name) 
    if ($gtype -eq "global") 
    { 
     # Global Distribution Group 
     [Void] $objDsGroup.Put("groupType", 0x80000002) 
    } 
    elseif ($gtype -eq "dlg") 
    { 
     # Domain Local Distribution Group 
     [Void] $objDsGroup.Put("groupType", 0x80000004) 
    } 
    elseif ($gtype -eq "uni") 
    { 
     # Universal Security Group 
     [Void] $objDsGroup.Put("groupType", 0x80000008) 
    } 
    else 
    { 
     Write-Host("Invalid group type {0}" -f $gtype) 
    } 
    [Void]$objDsGroup.SetInfo() 
    return $objDsGroup 
} 

function CreateDsObject([string] $server, [string] $container, [string] $name, [string] $objClass) 
{ 
$strConatinerPath = GetLdapPath -server $server -dn $container 
$objContainer = [adsi] $strConatinerPath 
$strChildCn = GetCn -name $name -objClass $objClass 
$strChildDn = "{0},{1}" -f $strChildCn, $container 
$strChildPath = GetLdapPath -server $server -dn $strChildDn 
$objChildEntry = $objContainer.Create($objClass, $strChildCn) 
[Void]$objChildEntry.SetInfo() 
    return $objChildEntry 
} 

function GrantGenericRead($dsTrustee, $dsResources) 
{ 
    $strSid = GetSid -dsObj $dsTrustee 
    $objSid = New-Object Security.Principal.SecurityIdentifier($strSid) 
    $ace = New-Object DirectoryServices.ActiveDirectoryAccessRule($objSid, $AD_RIGHT::GenericRead, $AC_TYPE::Allow) 
    [Void] $dsResources.psbase.ObjectSecurity.AddAccessRule($ace) 
    [Void] $dsResources.psbase.CommitChanges() 
} 

function GetSid($dsObj) 
{ 
    $dn = $dsObj.distinguishedName.Value 
    $binary = $dsObj.psbase.Properties["objectSid"].Value 
    $sid = New-Object Security.Principal.SecurityIdentifier($binary, 0) 
    return $sid.ToString() 
} 

$adminContainerDn = "OU=Zone Administration,{0}" -f $adminContainer.Get("distinguishedName") #returns OU=Zone Administration,OU=asdfasdf,DC=baldur,DC=vm 
$ouUnixGroups = CreateDsObject -server $server -container $ouDN -name $strOuUnixGroups -objClass "OrganizationalUnit" 
$joinOps = CreateADGroup -server $server -name "Join Operators" -container $adminContainerDn -gtype "global" 

GrantGenericRead -dsTrustee $joinOps -dsResources $ouUnixGroups 

그들을 생성하지 않는 스크립트에서 $joinOps$ouUnixGroups을 수정할 수있는 것입니다 : 그것은 모두 동시에 실행이 때

이 코드는 작동합니다. 어떻게 접근합니까? 나는 SID를 얻을 수 있지만, 내가 정말로 중요한 것을 놓치지 않는 한, 그것은 나를 돕는 것처럼 보이지 않는다.

GrantGenericRead -dsTrustee $joinOps -dsResources [adsi]$ouUnixGroups.Path 

나는 사람이보고 싶은 경우에 나는 http://pastebin.com/uF3nrDuw에 게시 한 설치 프로그램 스크립트에서이 라인의 일부를 당기는거야. u는

답변

1

당신은 시도 할 수 있습니다 :

GrantGenericRead -dsTrustee [adsi]"cn=Agroup,ou=AnOU,dc=dompn,dc=domp0" -dsResources [adsi]"ou=theUnixOU,ou=AnOtherOU,dc=dompn,dc=domp0" 
+0

내가 난 두려워 – matt

+0

내가 그 PS C 시도 것을 시도 두려워 : \ WINDOWS \ system32를> GrantGenericRead -dsTrustee가 [ADSI] $ joinOps합니다. Path -dsResources [adsi] $ ouUnixGroups.Path null 배열로 인덱싱 할 수 없습니다. 라인에서 4 문자 : 40 + $ 이진 = $ dsObj.psbase.Properties [<<<< "objectSID 특성"] 값 + CategoryInfo :. InvalidOperation (objectSID 특성 : 문자열), 런타임 예외 + FullyQualifiedErrorId : 가 가 [ADSI] $ ouUnixGroups.Path.psbase.objectsecurity.AddAccess 규칙 ($ 에이스) – matt

+0

먼저 이해해야하는 코드는 여기에서 제공 NullArray는 GETSID 방법에서, 여기에 아래로 떨어질 것으로 보인다 그룹과 OU를 만들려면 기존 개체를 GrantGenericRead aginst로 그냥 사용하고 싶습니까? 먼저 기존 객체의 DN 문자열을 하드 코딩하려고 했습니까? – JPBlanc

관련 문제