Security – Active directory list of users and “member of” from trusted domain

active-directorygroupsSecurityusers

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?

Best Answer

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)