Solved input vaules from a CSV file based on computer name

January 19, 2012 at 15:42:28
Specs: Windows 7
Hi guys
Bit of background, I have just taken over managing a site from another IT worker who has moved on, the issue is he deleted all of his self made scripts, I have recreated a lot of them but I am having issue with one very important script.

We have a CSV file that lists all the PC names in each column in excel that are currently active, this CSV file also has other fields of entry that go across the row based on the PC name:

The CSV info looks like this (sample not all of the CSV data (I have manually put in commas so it is easier to tell each row apart for the example))

11067DEDSTS, BDG - Bridgewater, Back Office, 11067DEDSTS, BW4 505, BWT80
11100DEDSTS, HNV - Huonville Cashier, 11101DEDSTS, HV3 583 HUO11
10373HPSTS DPT - Devonport RM 10376HPSTS DE1 170 DPT30

This state’s all the useful information for the machine
What I need is some of the values extracted out and the those values either to a file (or pref to a registry entry) based solely on the machine name the PC and it matching up to the PC name in the first row entry

(I’ll explain better if I can)

PC name, 11067DEDSTS,
Location, BDG - Bridgewater,
Class, Back Office,
Server PC for site, 11067DEDSTS,
ID, BW4,
Till, 505,
Till Location, BWT80

What I need is if the PC name of the actual PC matches any of the entry (EG the PC name matches the one from the line above) I need to output the Till and Till location to specific spots in the registry (or just to notepad files and I can do the rest) and if the PC name doesn't match one in the list is does nothing.

Please let me know if you need more info but I would appreciate the help the old admin left me in a massive bind.

EDITED: hopefully to make the description of what each value is easier to read.

See More: input vaules from a CSV file based on computer name

Report •

January 20, 2012 at 08:37:57
Are the till and the till location always in the same column on the csv?

Report •

January 22, 2012 at 13:31:03
yes it will always be in the same location, sorry i apoligise for not explaining that.

edit: to be a bit more useful
in the Rows they will alway go
PC name|Location|Type|Site Server|Name|Till|Till-ID|

Report •

January 23, 2012 at 07:17:21
✔ Best Answer
This should pull out the Till and Till-ID. If you want, instead of outputting to a file, you could output to variables and then create that .reg file you wanted. Let me know if you need help with that.

@echo on
set /p hostnm=What is the name of the computer you are looking for?
for /f "tokens=1,2,3,4,5,6,7 delims=," %%a in (csv.csv) do (
if %%a equ %hostnm% echo %%a - %%f - %%g > output.txt

Report •

Related Solutions

January 23, 2012 at 14:01:42
As a side question on this, if I have a text file with the PC name I want already generated (by another script) can I auto fill that set /p hostnm= command with it (so the user can just either hit enter to go with that PC or delete it to search for another PC) ?

Also if I wanted to then take the Till and ID file from here and dump then into a registry could I and how.

Thank you so much for your help so far I hope I’m not asking too much of you.

Report •

January 23, 2012 at 21:44:37
It's no problem Rykon. I'm glad I can help. Here is a modified version that looks for a hostname in file_containing_hostname.txt, and then asks if that's the one you want to use. Test it for me and let me know if it works. Can you post an example of the reg key you need to modify/create? Once I have that, I can modify the output to create the reg file.

@echo off
set /p hostnm=<file_containing_hostname.txt
if defined %hostnm% goto prompt
set /p choice=Is %hostnm% the name of the computer you are looking for (yes,y,no,n)?
if %choice% equ y goto loop
if %choice% equ n goto prompt
if %choice% equ yes goto loop
if %choice% equ no goto prompt
echo %choice% is not a valid entry. Restarting script in 5 seconds...
timeout 5
goto start
set /p hostnm=What is the name of the computer you are looking for?
for /f "tokens=1,2,3,4,5,6,7 delims=," %%a in (csv.csv) do (
if %%a equ %hostnm% echo %%a - %%f - %%g > output.txt

Report •

January 24, 2012 at 14:21:08
I really don't know how to thank you, you have saved me about a hours worth of work (combining this with other working scripts) for each PC i have to change so in total about 2 hours every week, thank you so much

Report •

Ask Question