2014-09-11 2 views
0

저는 보안 감사를 위해 AD의 정보를 쿼리하는 DBA입니다. 모든 AD 개체를 CSV에 넣고 다른 도메인에서 외부 보안 주체를 확인할 수있는 보고서를 만들어야합니다. 도메인 간에는 신뢰가 있습니다. 나는 스크립트에서 오는 PowerShell에서 작업을 다음 있습니다 :AD보고를위한 두 개의 powershell 스크립트를 외래 보안 주체와 결합하는 방법

$D = [System.DirectoryServices.ActiveDirectory.Domain]::GetCurrentDomain() 
$Domain = [ADSI]"LDAP://$D" 
$Searcher = New-Object System.DirectoryServices.DirectorySearcher 
$Searcher.PageSize = 200 
$Searcher.SearchScope = "subtree" 
$Searcher.SearchRoot = "LDAP://" + $Domain.distinguishedName 

# Specify attributes to retrieve. 
$Searcher.PropertiesToLoad.Add("distinguishedName") > $Null 
$Searcher.PropertiesToLoad.Add("sAMAccountName") > $Null 

# Hash table. 
$MemberList = @{} 

# Retrieve all users, groups, and computers. 
$Searcher.Filter = "(|(objectCategory=user)(objectCategory=group)(objectCategory=computer))" 
$Results = $Searcher.FindAll() 
ForEach ($Result In $Results) 
{ 
$DN = $Result.Properties.Item("distinguishedName") 
$Name = $Result.Properties.Item("sAMAccountName") 
$MemberList.Add($($DN), $($Name)) 
} 

# Filter on all groups. 
$Searcher.Filter = "(objectCategory=group)" 
$Searcher.PropertiesToLoad.Add("member") > $Null 

$Results = $Searcher.FindAll() 
ForEach ($Result In $Results) 
{ 
$Name = $Result.Properties.Item("sAMAccountName") 
$Line = """DN,$Name""" 
$Members = $Result.Properties.Item("member") 
ForEach ($Member In $Members) 
{ 
    If ($MemberList.ContainsKey($Member)) 
    { 
     # Substitute the sAMAccountName from hash table. 
     $Line = $Line + ",""" + $MemberList[$Member] + """" 
    } 
    Else 
    { 
     # Use the Distinguished Name. 
     $Line = $Line + ",""" + $Member + """" 
    } 
} 
$Line 
} 

http://social.technet.microsoft.com/Forums/scriptcenter/en-US/59d99252-2b1c-490e-818c-d1a645332293/powershell-ad-group-membership?forum=ITCG&prof=required 그럼 내가 스크립트 http://activelydirect.blogspot.com/2011/01/dealing-with-foreignsecurityprincipal.html#comment-form에서 오는 발견, 내 희망은 내가 처음 스크립트에 다음을 추가하고이를 해결하기 위해 얻을 수있다. 그러나 모든 입력을 환영합니다. 귀하의 질문에, 다음 네, 좋은 결과를 이렇게 유사한 코드를 사용자 이름으로 신뢰할 수있는 도메인에서 외국 보안 원칙으로 변환하는 두 번째 스크립트 작업을 사용하는 것이다 경우

$securityPrincipalObject = New-Object System.Security.Principal.SecurityIdentifier($object.cn) 
    ($domain, $sAMAccountName) = ($securityPrincipalObject.Translate([System.Security.Principal.NTAccount]).value).Split("\") 

답변

1

. System.Security.Principal.SecurityIdentifier 생성자에 전달한 내용이 FSP (예 : "S-1-5-21 -...")의 SID이고 distinguishedName 또는 "CN = S- 1-5-21 -... ".

UPDATE : 설명

if ($dN.StartsWith("CN=S-")) 
    { 
    $SIDText = ($dN.Split(","))[0].SubString(3) 
    $SID = New-Object System.Security.Principal.SecurityIdentifier $SIDText 
    Write-Output $SID.Translate([System.Security.Principal.NTAccount]).Value 
    } 
else 
    { 
    Write-Output $dN 
    } 
+0

감사합니다. 광고 보안 구조 및 쿼리는 모두 내게 외국입니다. 비슷한 코드를 기꺼이 공유하거나 두 스크립트를 병합하는 데 도움이됩니까? 내 지식이 이런 종류의 구문을 제한합니다. – dbahiker

+0

내가하는 일은 distinguishedName에 대한 단순한 테스트로 외래 보안 주체처럼 보이는지, 번역되어 있는지 확인하는 것입니다. distinguishedName 자체를 출력 할 때마다 비슷한 테스트를 삽입 할 수 있습니다. 내 대답에 코드 샘플을 추가했습니다. – tyork

+0

나는 내일 아침에 그것을 체크하고 대답을 표시 할 것이다. – dbahiker

관련 문제