A Quick Tip To Get Members Of Security Groups

by [Published on 17 Sept. 2009 / Last Updated on 4 April 2009]

This article explains a command which you can use to get the members of security group or security groups mentioned in a text file.

The below command can be used to get the list of members of a security groups mentioned in a text file. This is very useful when you want a list of user accounts for Security Groups.


  1. Create a text file: GroupNames.txt
  2. Copy all the group names (do not copy the DN of the Group, only the group name. For example, Administrator)
  3. Run the following command:

For /f "Tokens=*" %a in (GroupNames.txt) Do DsQuery group -name "%a" | DsGet group -members -expand > GroupName_%a.txt

The above command will create a file by that group name and all the members of that group will be saved in that group file.

Required files:

Please make sure you have the below mentioned files on the computer where you are running the above command.

  • DSQuery
  • DsGet

See Also

The Author — Nirmal Sharma

Nirmal Sharma avatar

Nirmal Sharma is a MCSEx3, MCITP and was awarded the Microsoft MVP award in Directory Services and Windows Networking. He specializes in Microsoft Azure, Office 365, Directory Services, Failover Clusters, Hyper-V, PowerShell Scripting and System Center products. Nirmal has been involved with Microsoft Technologies since 1994. In his spare time, he likes to help others and share some of his knowledge by writing tips and articles on various sites and contributing to PowerShell-based Dynamic Packs for www.ITDynamicPacks.Net solutions.

Featured Links