Computing.Net > Forums > Windows XP > CMD:Setting result dsquery as a var

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

CMD:Setting result dsquery as a var

Reply to Message Icon

Name: blink
Date: August 8, 2006 at 00:08:38 Pacific
OS: XP
CPU/Ram: Present
Product: .
Comment:

Is there a way to set the result of a dsquery command as a variable?

I want to get the full CN name of a computer through the following command:

dsquery computer -name [workstation]

The result of this I want set as a variable.



Sponsored Link
Ads by Google

Response Number 1
Name: Mechanix2Go
Date: August 8, 2006 at 02:08:14 Pacific
Reply:

Help me out here. I never heard of dsquery. So what *IS* the out put?

If it writes something ineteresting to stdout, you could work with that.

For example, if I wanted to set a var to the total disk space reported by chkdsk, I could do this:

::== f2.bat
chkdsk s:|find "total disk space" > #
for /f "tokens=1" %%T in ('type #') do (
set myvar=%%T
)
:: DONE


If at first you don't succeed, you're about average.

M2


0

Response Number 2
Name: blink
Date: August 8, 2006 at 02:40:45 Pacific
Reply:

The result of dsquery is the workstations CN:

"CN=W0849651,OU=Standard Desktops,OU=CLS,OU=SDK,DC=directory,DC=local"

As you can see, this sometimes includes spaces. The code you provided tends to stop after the first space.


0

Response Number 3
Name: Mechanix2Go
Date: August 8, 2006 at 03:00:26 Pacific
Reply:

Is that output ONE LINE?

Do you want to use the whole line?

[I assume it does not include the quotes.]


If at first you don't succeed, you're about average.

M2


0

Response Number 4
Name: blink
Date: August 8, 2006 at 07:39:21 Pacific
Reply:

Yes, its one line and I want to use the whole line.

[it actually does include the quotes]


0

Response Number 5
Name: Mechanix2Go
Date: August 8, 2006 at 08:07:30 Pacific
Reply:

Try this:

dsquery computer -name [workstation]> #
set /p myvar=<#


If at first you don't succeed, you're about average.

M2


0

Related Posts

See More



Response Number 6
Name: blink
Date: August 10, 2006 at 03:04:20 Pacific
Reply:

It works!
Brilliant thanks!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Installing new stuff Blocking porn emails



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Windows XP Forum Home


Sponsored links

Ads by Google


Results for: CMD:Setting result dsquery as a var

setting up a proxy as a bot www.computing.net/answers/windows-xp/setting-up-a-proxy-as-a-bot/134930.html

set as a desktop..... www.computing.net/answers/windows-xp/set-as-a-desktop/52868.html

Setting a printer as a slave in XP www.computing.net/answers/windows-xp/setting-a-printer-as-a-slave-in-xp-/57907.html