I've been trying to create a csv file of all the members of an AD but since some groups have members from another trusted domain, these users are not showing up. I also tried outputting users in a text file by using:

dsquery group -name "Group Account Name" | dsget group -members -expand > C:users.txt 

and failing. Does someone know if what I'm trying to do is possible?


Your Dsquery syntax is missing the domain root LDAP path. It should look like:

dsquery group "DC=contoso,DC=com" -name "group name" | dsget group -members -expand > C:\Users.txt

Try with the updated syntax.

As per sysadmin1138's suggestion, here would be the command sent to a variable array "$members":

$members = (dsquery group "DC=contoso,DC=com" -name "group name" | dsget group -members -expand)
| improve this answer | |
  • I tried pasting the script that I am using but it won't let me since its too big to show here. Basically I am using Powershell and the command is = Get-ADUser -Filter * -Properties * etc.. Can I use dsquery instead? – Joshua Vella Aug 30 '11 at 14:34
  • By the way your syntax worked perfectly. But we have a lot of groups, is it possible with the script I got from stackoverflow.com/questions/4381943/… ? – Joshua Vella Aug 30 '11 at 14:44
  • @JoshuaVella In my experience dsquery is a lot faster than native PowerShell utilities for doing mass enumeration. What's better, is that dsquery can pass things into PowerShell datastructures very cleanly. Do the above and instead of piping to a file, send to a variable and you'll get an array. – sysadmin1138 Aug 30 '11 at 15:14

"all the members of an AD" - Should that be "AD group"?

If so, using the Active Directory Module for Windows PowerShell, you could issue the following command:

Get-ADGroupMember "Group Account Name" | out-file users.txt

If you'd like to get all members of all groups (per your comment), do the following:

Get-ADGroup -Filter * | Get-ADGroupMember | Where{$_.objectClass -eq "user"} | select * -unique | out-file users.txt

If you need to recurse through nested groups, add the -recursive switch to the GetADGroupMember cmdlet.

| improve this answer | |
  • Maybe I was not clear sorry. We have 2 domains in a trust relationship. I am trying to "get member of" each user from the local domain but the thing is, the groups are on the other domain where I am running the script. If I run the script on the local one, it does not show the groups for the users. – Joshua Vella Aug 30 '11 at 14:20
  • Your syntax worked. Is it possible to create the list for all the groups and not specifying a group yourself? – Joshua Vella Aug 30 '11 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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