@echo off
set /p name=Please enter name:
echo You entered: %name%
Main Topics
Browse All TopicsHi all,
Very simple i'm sure but I want to know how to pass in a variable into a batch file to put into a DSQUERY command.
Broken down, I want to make life easier for the 1st line supports in regards to password changing. If I can have a batch file they can double click on, it asks for the username they are trying to find the full name of, they enter it and then the results are displayed that would be ideal.
Then they would simply copy and paste the CN and use that for the DSMOD & -pwd switch to change the password.
But the point is, does anyone know how to pass in these strings into that command?
Thanks if you can help.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
x-men
The asker states:
>>"....a batch file they can double click on, it asks for the username...."
otherwise, normally, I would do the following:
@echo off
set name= <-- can hardcode the name here
if not "%1"=="" set name=%1 <-- passing argument will override hardcoded name
if not defined name ( <-- tests if name is set otherwise will prompt for it
set /p name=Enter name:
)
::
:: rest of code....
::
Would anyone know the best way to use the data outputted as a string on the dsquery results to pick out bits and use in another command straight after?
The dsquery command produces results (CN details DC details etc) that DSMOD needs to carry out the pwd change.
What would be the easiest way to grab/use these details?
I've split the whole line up into 12 parts (a through l)... use whichever ones you need. For example, if you only want CN and the domanin name then you only need to use: %%b and %%f - the rest can be omitted.
@echo off
:: split output into 12 parts assigning them to individual variables:
for /f "tokens=1-12 delims=,=" %%a in ('dsquery user domainroot -name Kinton*') do (
set label_cn=%%a
set cn=%%b
set label_ou=%%c
set ou=%%d
set label_dc1=%%e
set dc1=%%f
set label_dc2=%%g
set dc2=%%h
set label_dc3=%%i
set dc3=%%j
set label_dc4=%%k
set dc4=%%l
)
:: example using all the variables created:
echo.
echo %label_cn:~1% = %cn%
echo %label_ou% = %ou%
echo %label_dc1% = %dc1%
echo %label_dc2% = %dc2%
echo %label_dc3% = %dc3%
echo %label_dc4% = %dc4:~0,-1%
Business Accounts
Answer for Membership
by: t0t0Posted on 2009-09-08 at 03:09:28ID: 25280165
@echo off
set /p name=Please enter name:
dsquery user domainroot -name %name%*