An active directory group is a collection of active directory objects. It contains users, computer accounts, and other groups.
The Dsquery group command is used to find the group objects in the active directory that matches the specified search criteria.
Using the dsquery group command, it finds the objects in the active directory and uses the dsget user command to get all users in the group.
In this article, we will discuss how to use dsquery to get all users in the group in the active directory.
Using dsquery to list all users in the group
To list all users in the group, use the dsquery group command with the specified group name.
dsquery group -name "SalesLeader" | dsget group -members -expand | dsget user -samid -fn -ln -display
In the above command, the dsquery group command uses the name parameter with the value SalesLeader to get all users in this group only.
It then uses dsget group -members to get all the members in the group. dsget user command displays the user displayname, first name, last name, and samid.
The output of the above command is as given below:
Cool Tip: How to use the get list of all users in domain and OU using dsquery!
Use dsget to get all users in the group
Use the dsget group and dsget user command to retrieve a list of all users in the group.
In the below query, the dsget group command uses the DN name of the group to get group members of the group and passes the output to the dsget user command to list all users in the group.
dsget group "CN=SALESLeader,OU=SALES,DC=SHELLPRO,DC=LOCAL" -members -expand | dsget user -display
The output of the above command to list all users in the group is given below
The above command gets all the users from the group and display user name.
Cool Tip: How to use the dsquery * command to get user last logon!
I hope the above article on how to get a list of all users in the group using the dsquery group command is helpful to you.
Using the dsquery user command, you can find all groups user is a memberof.