Solved

list users in groups in OU

Posted on 2015-01-22
10
125 Views
Last Modified: 2015-02-05
Hey Experts.

I would like to show the users in the various groups within a particular OU.

Department (OU)
>Computers (OU)
>Groups (OU)
>>PRT-1 (Group)
>>PRT-2 (Group)
>>PRT-3 (Group)

I want to have the users that are in the groups nested in the "Department OU > Groups OU" output to a log file.  I need to know the users listed in the particular group:

PRT-1
-userA
-userB

PRT-2
-userA
-userC
-userD

Thanks experts!!
0
Comment
Question by:samiam41
  • 5
  • 4
10 Comments
 
LVL 23

Expert Comment

by:NVIT
ID: 40564916
Note: Change YourDomainName to your actual domain name.

From the DC, try:
dsquery user "CN=PRT-1,OU=Groups,OU=Computers,DC=YourDomainName,DC=com"

If that works, try this at CMD prompt:
for /f "tokens=1-2 delims==," %a in ('dsquery user "CN=PRT-1,OU=Groups,OU=Computers,DC=YourDomainName,DC=com"') do (echo %~b)
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40564935
Actually, change that to dsget group "CN=GroupName,DC=domain,DC=name,DC=com" -members
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40564998
This should get you where you want to be.

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=Groups,DC=Domain,DC=com" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.txt
::pause
for /f "tokens=1-2 delims==," %%a in ('dsget group %ougroup% -members ^|sort') do (echo %%~b >>ou-group-members.txt)
goto :eof

Open in new window

0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40565010
This will be a little nicer output file.

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=Groups,DC=Domain,DC=com" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.csv
::pause
for /f "tokens=1-2 delims==," %%a in ('dsget group %ougroup% -members ^|sort') do (echo ,%%~b >>ou-group-members.csv)
goto :eof

Open in new window

0
 
LVL 9

Author Comment

by:samiam41
ID: 40565161
Great script!

Here is what I used:

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=Groups,DC=Domain,DC=com" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.csv
::pause
for /f "tokens=1-2 delims==," %%a in ('dsget group %ougroup% -members ^|sort') do (echo ,%%~b >>ou-group-members.csv)
goto :eof

Open in new window


The log file shows the username as:  lastname\

Not the user name.  How can I (we/you) fix that?
0
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 13

Accepted Solution

by:
Gabriel Clifton earned 500 total points
ID: 40565511
There may be a better way, but I do know this works.

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=Groups,DC=domain,DC=com" ^|sort') do (call :oumembers %%a)

exit /b

:oumembers
set ougroup=%1
echo %ougroup% >>ou-group-members.csv
::pause
for /f "tokens=*" %%b in ('dsget group %ougroup% -members ^|sort') do (call :usersamid %%b)
goto :eof

:usersamid
set userid=%1
for /f "tokens=*" %%c in ('dsquery user %userid% -o samid') do echo ,%%c >>ou-group-members.csv
goto :eof

Open in new window

0
 
LVL 9

Author Closing Comment

by:samiam41
ID: 40566989
Brilliant work!!  Thanks for your help with this!
0
 
LVL 13

Expert Comment

by:Gabriel Clifton
ID: 40567162
No problem, any time.
0
 
LVL 9

Author Comment

by:samiam41
ID: 40567167
Check this question out if you have some time and want some points!

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28602773.html
0
 
LVL 9

Author Comment

by:samiam41
ID: 40592098
Hey everyone!  I have a question that received a couple of replies but the suggestions are for powershell and I asked for batch.  If any of you have a minute or two and would like some points, I would appreciate your help.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28610287.html
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You may have already been in the need to update a whole folder stucture using a script. Robocopy does it well and even provides a list of non-updated files in a log (if asked to). Generally those files that were locked by a user or a process by the …
You may have a outside contractor who comes in once a week or seasonal to do some work in your office but you only want to give him access to the programs and files he needs and keep privet all other documents and programs, can you do this on a loca…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
This Micro Tutorial will teach you how to change your appearance and customize your Windows 7 interface to your unique preference. This will be demonstrated using Windows 7 operating system.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now