Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

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|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.