Export nested groups a contact is a memberOf
<p>I'm using Exchange 2010 and Powershell.</p>

<p>I'm looking to export all 'nested' distribution groups that a exchange contact is a part of. </p>

<p>For example, if a contact is a memberOf two DG, A and B. And group A is also a memberOf Group C. I'd like a list the show all three groups. </p>

<pre><code>      Group C      
    ----|-----------|
     Group A     Group B
             |
          Contact
</code></pre>

<p>Here is my very noob attempt at this. I guess it needs to be done recursively?</p>

<pre><code>$contact = get-contact email@domain.com.au

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

foreach ($group in $members.MemberOf) {  

    foreach ($_ in $group.memberof ){ 

    get-distributiongroup $_ 

    }
}
</code></pre>

<p>Must be able to do this for a 'contact', not a user.</p>

<p>Thanks in advance!</p>