# Building a batch file to pull from a source text file



## SithHunter (Feb 4, 2015)

Hi everybody.

I've been beating my head off the desk for a while now and just haven't been having any luck.

I need to use 'getmac' to pull the MAC addresses of a list of 200+ machines in our campus labs and have it create an output table or csv file that contains the hostname and the MAC.

I can get the command itself to execute but can't find a way to get it to dump the hostname in as well. I've been thinking about specifying a variable and then writing it into the output file on each line but haven't had much luck in that department either.

This was dumped into my lap this afternoon with the expectation that the output be ready by noon tomorrow and unfortunately I'm not a system admin and scripts have been blocked from running on the systems I have access to, so Powershell isn't an option.

What I have that works for individual entries is:

set /p id=Hostname:
getmac /s %id% > c:\output\%id%.txt

The end result isn't ideal but it will do the job if I can get it to draw the initial variable input from a list file with one hostname per line separated by a carriage return.

If anyone can help me out with this I would greatly appreciate it.


----------



## foxidrive (Oct 20, 2012)

A machine can have more than one NIC or a VM with an emulated NIC.
How will you determine that?

Knowing the format of the input file would help too.


----------



## SithHunter (Feb 4, 2015)

Hi Fox,

The format of the input file is strictly one hostname per line.

All of the machines have a single NIC with no VMs in the mix.

Right now, my biggest issue is that the command 'getmac /s "hostname" > c:\output\"hostname".txt will work from a command prompt but as soon as I try to run it from a batch, it's echoing the output to the screen and creating a blank txt file with the correct name and I can't for the life of me figure out why.


----------



## foxidrive (Oct 20, 2012)

I can't check remote machines here, and may not have the same OS version
so it would be useful if you would paste the output from one command in a reply,
to determine what needs to be parsed out of the text.

The command output can change in different versions - it's a waste of time to
code something without seeing the real data in the setting it is being used.


----------



## Squashman (Apr 4, 2003)

I got a couple of servers at my disposal. [eVil Laugh]

I will test it out.


----------



## Squashman (Apr 4, 2003)

```
@echo off
FOR /F "delims=" %%G IN (computernames.txt) DO (
	FOR /F "tokens=1 delims=," %%I in ('getmac /s "%%G" /u domain\username /p pasword /NH /FO CSV') DO (
		>>computer_macs.txt echo %%~G,%%~I
	)
)
```


----------



## Squashman (Apr 4, 2003)

Did this work for you?


----------

