title: get list of DLs few users are member of
body: <p>I am beginner in powershell and trying to create a script.
  I have list of users, for them I need to know in which DLs they are added.</p>
  <p>The problem I am facing is, it shows the list of DLs only, is there any way I can get DLs under the usernames? or a better way to accomplish this.</p>
  <p>Note: we name all our  DLs in capital letter thats why I have used &quot;\b[A-Z0-9_]+\b&quot; in where-object.</p>
  <pre><code>$users = import-csv C:\Test\users.csv | ForEach-Object {$_.users = $_.users.Trim(); $_}  | Select-Object -ExpandProperty users
  
  foreach ( $user in $users)
  
  {get-ADPrincipalGroupMembership $user | select name |
  
  Where-Object { $_.name -cmatch &quot;\b[A-Z0-9_]+\b&quot;} | Export-CSV &quot;C:\test\output_file.csv&quot; -NoTypeInformation -Append
  
  }
  
  </code></pre>
  <p>Now I get the following outcome:</p>
  <pre><code>Group1
  Group2
  Group3
  Group2
  Group3
  Group4
  
  </code></pre>
  <p>My ideal out put would be something along the lines of:</p>
  <pre><code>User  MemberOf
  ----  --------
  Bob   Group1, Group2, Group3....
  Jim   Group2, Group3, Group4....
  </code></pre>
  <p>Thanks alot.</p>