Batch file loop

March 24, 2009 at 11:33:06
Specs: Windows XP SP3

I have a small problem and need some help. We need to quickly find the MAC addresses of machines and all we have is the hostname.

We have been using the getmac /s \\computername command to get the mac address of a single hostname.

I have a text file which has lots of hostnames in it (150) one per line e.g.


I am using the following command

getmac /s hostname1 /u domain\user /p password /fo csv /nh >> ThisFile.txt

My question is, is there anyway to loop through the file using each line of the file as the hostname for example in the form of a variable. I'm not too hot with batch scripting so not great with loops any help would be much appreciated!!


See More: Batch file loop

Report •

March 24, 2009 at 13:08:26
Non-Command Script version:
FOR /F %a IN (SomeTextFile) DO getmac /s %a /u domain\user /p password /fo csv /nh >> ThisFile.txt
SomeTextFile's name cannot contain spaces.

Report •

March 25, 2009 at 01:03:28
Thank you this has me on the right track :-)

Report •

Related Solutions

Ask Question