how do I list Distribution Group (List) and their members inside of an OU using AD or exchange 2010

5,672

It's not very pretty, but this PowerShell should do it,

Import-Module ActiveDirectory

"{0},{1}" -f  "Group Name", "Member" | out-file outfile.csv
Get-ADGroup -filter * -SearchBase "ou=groups, dc=your, dc=domain" | ForEach-Object {
$group = Get-ADGroup $_.Name
foreach ($member in Get-ADGroupMember $group)
{
"{0},{1}" -f  $group.Name,$member.Name | out-file outfile.csv -append
      }
}

Update the SearchBase with the path to your target OU and away it should go.

Share:
5,672

Related videos on Youtube

wraak
Author by

wraak

Updated on September 18, 2022

Comments

  • wraak
    wraak over 1 year

    our entire domain has thousands of distribution groups, while i can use the script referenced here: How to get a list of all Distribution Lists and their Members in Exchange 2007? to pull all distribution groups and their members, it would be too hard to filter through all results.

    I particularilly need to pull either a. (preferred) all groups (both distribution and security) and their members inside of an OU (this particular OU contains over 100 hundred groups) or b. all groups and members matching a name starting with exampl*

    dsquery | dsget looks like could almost serve that purpose however when i did:

    dsquery group "OU=my-department,DC=blah,DC=blahblah,DC=com" -name * | dsget group -members (-expand) >> c:\my-department.txt

    it displays only the members without showing which group they belong to. The output I need should have: group name, members and potentially expanded sub-groups.

    i am still researching on how to get this done, seems like i can somehow make the above referenced script to search only inside of an OU, but i am not very familiar with powershell.

    any help would be appreciated, thank you.