March 31 2010

Query to show members of an AD group

You’ll often need a quick way to get the names of users in a particular Active Directory group into a text or Excel file for reporting or other reasons. You can use dsquery to achieve this easily:

dsquery group -name "group name" | dsget group -members -expand | dsget user -fn -ln

Of course you can also change the ‘dsget user -fn -ln’ to display or remove attributes, eg ‘dsget user -samid’ will show the username. You can also pipe this into a text file.

I use a maximum of one Google Ad per post to help offset some of my blog hosting costs.


Tags: , , , , , , ,

Posted March 31, 2010 by danovich in category "Scripting", "Tools", "Windows


  1. By John Rothlisberger on

    You don’t get any nested members though — only the immediate members.

  2. By danovich (Post author) on

    Yes, that’s right – unfortunately in this case we’d need to drop the last dsget command and just use ‘dsquery group -name “group name” | dsget group -members -expand’ then do a bit of manual manipulation in Excel!


Leave a Reply