Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a user group and user audit/review process. For this I am looking for a script that can easily generate a list of groups and the assigned users. E.g.:


locked by voretaq7 Mar 19 '15 at 18:12

This question exists because it has historical significance, but it is not considered a good, on-topic question for this site, so please do not use it as evidence that you can ask similar questions here. This question and its answers are frozen and cannot be changed. More info: help center.

closed as off-topic by TheCleaner, mdpc, voretaq7 Mar 19 '15 at 18:12

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

Are you looking for domain groups or local computer groups? and do you have to worry about nested groups? – Rex Mar 26 '12 at 3:35

You can use net localgroups to get a list of groups on the local machine, and net user to get a list of users. You can then use net user USERNAME to get a list of groups that the user is in. It will require a bit of scripting to put it all together though.


Paste this text in a batch file:

  @echo off

  for /f "delims=*" %%a in ('dsquery user -name * -limit 12000^|dsget user -samid') do Call :ShowUser %%a
  goto :eof

    set usr=%*
    If "%usr%"=="dsget succeeded" goto :eof
    for /f "delims=*" %%b in ('dsquery user -name * -limit 12000^|dsget user -memberof^|dsget group -samid') do if NOT "%%b"=="dsget succeeded" Echo %usr%  %%b

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