Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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.:

Administrators/Administrator
Administrators/Account1
Administrators/Account2
SomeOtherGroup/Accounts2
share

locked by voretaq7 Mar 19 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 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

2 Answers 2

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.

share

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

  :ShowUser
    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
share

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