2016-07-15 4 views
1

Exchange 2010 및 Powershell을 사용하고 있습니다.중첩 그룹 내보내기 연락처가 구성원 인 경우

교환 연락처가 포함 된 모든 '중첩 된'메일 그룹을 내보내려고합니다.

예를 들어 연락처가 DG, A 및 B의 두 구성원 인 경우. 그룹 A도 memberOf 그룹 C입니다. 목록에서 세 그룹을 모두 표시하고 싶습니다.

 Group C  
    ----|-----------| 
    Group A  Group B 
      | 
      Contact 

여기 내 아주 멍청한 시도입니다. 재귀 적으로 수행해야 할 필요가 있습니까?

$contact = get-contact [email protected] 

$members = Get-ADObject -Identity $contact.Guid -Properties 'MemberOf' 

foreach ($group in $members.MemberOf) { 

    foreach ($_ in $group.memberof){ 

    get-distributiongroup $_ 

    } 
} 

사용자가 아닌 '연락처'에 대해이 작업을 수행 할 수 있어야합니다.

미리 감사드립니다.

답변

0

메일 그룹을 가져 오기 위해 Exchange가 필요하지 않습니다.

function Get-GroupsRec 
{ 
[CmdletBinding()] 
param(
[Parameter(ValueFromPipeline=$true)] 
$Identity 
) 
BEGIN {} 
PROCESS{ 
    if($Identity -eq $null){return} 
    Write-Output $Identity | select -ExpandProperty samaccountname 
    $Identity | Get-ADPrincipalGroupMembership | ?{$_.GroupCategory -eq "Distribution"} | Get-GroupsRec} 
END{} 
} 
Get-ADUser -Filter {mail -eq '[email protected]'} | Get-ADPrincipalGroupMembership | ?{$_.GroupCategory -eq "Distribution"} | Get-GroupsRec 

그러나만큼 당신이 AD 사용자를 검색 할 수 있습니다,이 솔루션은 유효합니다 다음 연락처를 가정 그룹의 이름을 검색하기 위해 내 예제 작성 메일 속성 AD 사용자입니다.

업데이트 : 버전은 Get-ADObject을 기준으로합니다. (동일 구조 만 다른 선택기 왼쪽 ObjectClass를 필터 가독성합니다.) : 특정 유형 그룹 유형을 제한하려는 경우 -band 연산자의 값으로 코드에서 GroupType을 수정할 수 있습니다

function Get-GroupsRec 
{ 
[CmdletBinding()] 
param(
[Parameter(ValueFromPipeline=$true)] 
$Identity 
) 
BEGIN {} 
PROCESS{ 
    if($Identity -eq $null){return} 
    Write-Output $Identity | select -ExpandProperty Name 
    $Identity | select -ExpandProperty MemberOf | Get-ADObject -Properties GroupType,MemberOf |?{$_.GroupType -gt 0 -and $_.ObjectClass -eq 'group'} | Get-GroupsRec } 
END{} 
} 
Get-ADObject -Filter {mail -eq '[email protected]'} -Properties MemberOf | select -ExpandProperty MemberOf | Get-ADObject -Properties GroupType,MemberOf |?{$_.GroupType -gt 0 -and $_.ObjectClass -eq 'group'} | Get-GroupsRec 

. 열거 자 값은 https://msdn.microsoft.com/en-us/library/aa772263(v=vs.85).aspx

+0

안녕하세요 Deptor, 해답을 제공해 주셔서 감사합니다. 연락처에는 mail 속성이 채워져 있습니다. 아직 PS에 익숙하지 않으므로 코드를 따르는 데 문제가 있습니다. 스크립트를 테스트했지만 오류가 발생하지 않았지만 결과물도 없습니다. – jez

+0

@jez 전혀 아나요? 첫째, 코드의 마지막 줄에 변수를 할당하지 않았습니까? 그러면 출력이 표시되지 않습니다. 둘째, 각 부분별로 마지막 줄을 실행하여 원인을 찾아내는 것이 좋습니다 (각 '|'로). 이 함수는 재귀에 대해서만 책임을집니다. – Deptor

+0

@jez가 코드를 수정했습니다. 함수의 작은 실수를 수정하고 선택된 속성을 비어 있지 않은 것으로 변경했습니다. – Deptor

0

에서 사용할 수 있습니다. 당신은 실제로 이것에 대한 재귀가 필요합니다. 나는 재빨리 회원 자격을 무너 뜨릴 수있는 무엇인가를 빨리 집어 넣는다. 희망이 도움이!

Function Get-Groups { 
    Param(
     [string]$Identity 
    ) 

    $members = Get-ADObject -Identity $Identity -Properties "MemberOf" 
    $members.MemberOf | % { 
     if($(Get-ADObject $_ -Properties "GroupType").grouptype -gt 0) { 
      Write-Host $_ 
     } 
     Get-Nestedmember $_ "->" 
    } 
} 

Function Get-Nestedmember { 
    Param(
     [String]$Identity, 
     [string]$Depth 
    ) 
    $members = (Get-ADobject -Identity $Identity -Properties "MemberOf").memberof 
    $count = $members | measure 
    if($count -ne 0) { 
     $members | % { 
     if($(Get-ADObject $_ -Properties "GroupType").grouptype -gt 0) { 
      Write-host "$Depth $_" 
     }  
      Get-Nestedmember $_ "-$Depth" 
     } 
    } 
} 
Get-Groups -Identity '<Your Identity goes here>' 

이것은 MemberOf 관계를 가져오고 결과 집합에 대해 다시 수행합니다. MemberOf가 0을 반환하면 더 이상 MemberOf 관계가 없으므로 중지합니다.

+0

함수는 보안 그룹도 반환합니다. 질문은 배포 만 언급합니다. – Deptor

+0

@Deptor 그 대답을 수정했습니다. – Fairy

+0

감사합니다.하지만 문제는이 검색이 사용자가 아닌 특정 연락처/이메일 주소 일 것입니다. 예를 들어, John Doh - [email protected] 연락처와 함께 'Get-ADObject -Identity'를 사용하면 'ID가있는 개체를 찾을 수 없습니다 ...'라는 문제가 발생합니다. – jez

관련 문제