insert code to prompt for OU to audit

Hey experts.  Here is the code I am using to dump out the users in all the groups for a particular OU.

@echo off
cls

for /f "tokens=*" %%a in ('dsquery group "OU=x,DC=y" ^|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


I would like to have the script prompt for what OU to audit.  How can I do this?

Thanks Experts!
LVL 9
samiam41Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Bill PrewConnect With a Mentor Commented:
Give this a try:

@echo off
cls

set OU=
set /p "OU=Please enter OU name: "
if "%OU%" EQU "" (
  echo No OU name entered, ending.
  exit /b
)

for /f "tokens=*" %%a in ('dsquery group "OU=%OU%,DC=y" ^|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
 
QlemoDeveloperCommented:
To get a prompt, use
set /p ou=Please enter OU to dump 

Open in new window

This sets %ou% .
0
 
samiam41Author Commented:
Clean and implemented it already.

Thank you for your help!

Qlemo, he got there first.  Hope you understand.
0
 
samiam41Author Commented:
A new question.  Thanks for your help if you have time.

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_28602795.html
0
All Courses

From novice to tech pro — start learning today.