1.

Solve : Cross Reference Company Name and Computer Name?

Answer»

Sorry if the title was misleading, I'm not really sure how to word what I want to do. I would like to add a command to a tool I use to manage our servers every day. The logic is this:

If the server NAME starts with set VARIABLE=Company Name. i.e. The script will need to be able to cross reference a list of server names and company names. The servers are named as such: TS888-101. The company associated with all TS888 servers is WIDGET Company. So If the first 5 characters in %computername% are TS888 SET CONAME=Widget Company

I'm nearly positive I can do this with a utility called SSR but I'm interested in how to do it without the help of a third party utility. Any ideas?

Thanks,

MJDo you have a file with the company names and codes?
Or do you want to hardcode all of this in a batch file?Squashman - I imagined using a text file - FarmID.txtQuote from: powlaz on June 14, 2013, 10:39:55 AM

Squashman - I imagined using a text file - FarmID.txt
And the format of this file will be???We can tell you how to compare parts of a string (set /? has INFO) but to give you something that will work for you depends on the file format, as Squashman said.Sorry, I disappeared. I've been very sick. I don't THINK I really put much thought into what was going to be in the file, just that there would be a file. Hmmmm . . . I'm not really sure how the file should read.

Could something like this work:

TS888-101=Widget Company
TS888-102=Widget Company
TS899-101=Gadget Company

etc.?

If not, can you suggest a format?

Thank,

MJThis should work with the format you listed above. It's untested:

Code: [Select]@echo off
set "name=%computername:~0,5%"
set "coname="
for /f "tokens=1,2,* delims==-" %%a in ('type "companylist.txt") do if "%name%"=="%%a" set "coname=%%c"

if defined coname (
echo from %name% the company found was "%coname%"
) else (
echo no company name was found
)
pause


Discussion

No Comment Found