samiam41
asked on
list users in groups in OU
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!!
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!!
Actually, change that to dsget group "CN=GroupName,DC=domain,DC =name,DC=c om" -members
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
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
ASKER
Great script!
Here is what I used:
The log file shows the username as: lastname\
Not the user name. How can I (we/you) fix that?
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
The log file shows the username as: lastname\
Not the user name. How can I (we/you) fix that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Brilliant work!! Thanks for your help with this!
No problem, any time.
ASKER
Check this question out if you have some time and want some points!
https://www.experts-exchange.com/questions/28602773/insert-code-to-prompt-for-OU-to-audit.html
https://www.experts-exchange.com/questions/28602773/insert-code-to-prompt-for-OU-to-audit.html
ASKER
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.
https://www.experts-exchange.com/questions/28610287/Add-members-in-one-group-to-another-group-via-script.html
https://www.experts-exchange.com/questions/28610287/Add-members-in-one-group-to-another-group-via-script.html
From the DC, try:
dsquery user "CN=PRT-1,OU=Groups,OU=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=Com