Sign in to follow this  
Followers 0
Prodigus

How do I create a variable from a called command?

8 posts in this topic

This is probably an easy thing for you pros but I'm just getting started at this (and can't stop)...

I'm trying to grab some information using logparser (a computers IP address) and I want the result of the Query (the IP address) to be $var2 (my variable name that I'm going to use.

$sCmd2Run2 = "logparser ""SELECT Value FROM ""\\23T7111\HKLM\SYSTEM\CurrentControlSet\Services\TCPIP"" WHERE ValueName = 'DhcpIPAddress'"" -i:REG -headers:off"

$sErrorStatus = RunWait($sCmd2Run2, @ScriptDir, @SW_HIDE)

if I run this it will return a IP address, I merely want that IP address to be automatically recognized as $var2

I don't want to have to place it in a txt file first and then read it out of there since I will be doing about 4000 of these and I would think all that opening and closing of the file would take away from my performance.

Any ideas?

Thanks!!

Share this post


Link to post
Share on other sites



what is the purpose of your software?..... it would be easiest to just show us some (full) source code :D

Share this post


Link to post
Share on other sites

what is the purpose of your software?..... it would be easiest to just show us some (full) source code :D

lol

The end result of the script I'm working on is not very exciting actually it will merely move computers around within Active Directory to different OU's based on their IP address and the "imagetype" registry key that our techs added to the administrative and clinical images of all machines in the enterprise.

The image type will tell me which top level OU it belongs to and then the IP address will tell me the geographical location of the machine. From that information I can keep machines in their proper OU's and thus they get their proper GPO's applied for that location and type. So even if someone moves a machine, I'll know....

But right now I'd just like to figure out how to take the results of a query and have it automatically recognized as a variable versus having to do that many reads and writes from another txt file.....

Thanks!!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

This is probably an easy thing for you pros but I'm just getting started at this (and can't stop)...

I'm trying to grab some information using logparser (a computers IP address) and I want the result of the Query (the IP address) to be $var2 (my variable name that I'm going to use.

$sCmd2Run2 = "logparser ""SELECT Value FROM ""\\23T7111\HKLM\SYSTEM\CurrentControlSet\Services\TCPIP"" WHERE ValueName = 'DhcpIPAddress'"" -i:REG -headers:off"

$sErrorStatus = RunWait($sCmd2Run2, @ScriptDir, @SW_HIDE)

if I run this it will return a IP address, I merely want that IP address to be automatically recognized as $var2

I don't want to have to place it in a txt file first and then read it out of there since I will be doing about 4000 of these and I would think all that opening and closing of the file would take away from my performance.

Any ideas?

Thanks!!

I'm not sure what you mean. Where is the IP address returned? From the command output? I don't know if this can be done with autoit, but you might consider vbscript wshshell.exec method (http://www.ss64.com/wsh/exec.html). Of course some of the resident autoit experts probably have a way to do it with autoit.

Edited by JMiller

Share this post


Link to post
Share on other sites

Yes, when you run this command with logparser it will return the IP address of the machine (as long as a) the machine is on and :D the IP was issued through DHCP.

"logparser ""SELECT Value FROM ""\\23T7111\HKLM\SYSTEM\CurrentControlSet\Services\TCPIP"" WHERE ValueName = 'DhcpIPAddress'"" -i:REG -headers:off"

That machine name is actually replaced by a variable in the actual script

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yes, when you run this command with logparser it will return the IP address of the machine (as long as a) the machine is on and :D the IP was issued through DHCP.

"logparser ""SELECT Value FROM ""\\23T7111\HKLM\SYSTEM\CurrentControlSet\Services\TCPIP"" WHERE ValueName = 'DhcpIPAddress'"" -i:REG -headers:off"

That machine name is actually replaced by a variable in the actual script

Hmm I think I might have found a function in autoit that works.. see nfwu's post below.

Script

I noticed he is using a command called StdoutRead() to get the command output.

Edited by JMiller

Share this post


Link to post
Share on other sites

I'll check it out.. Thanks!! :D

Share this post


Link to post
Share on other sites

I'll check it out.. Thanks!! :D

No prob btw I checked the help files in autoit and you have to pass the 4th parameter (2 for stdout) to the Run command to capture the output. It shows that in the above script, but it's easy to miss.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0