views:

77

answers:

1

Hello all,

We need to append a line to the hosts file for every user on our network. I have admin privileges, but don't know the first thing about windows scripting. Can someone point me in the right direction on this? I don't have the list of all the machine names, so I'd prefer a script that would discover all the machines on the network and do the update.

A: 

You can do it by batch file:

for %%x in (%0) do set BatchPath=%%~dpsx
for %%x in (%BatchPath%) do set BatchPath=%%~dpsx
FOR /F %%i IN (%BatchPath%\devices.txt) DO copy /B \\%%i\C$\WINDOWS\system32\drivers\etc\hosts + %BatchPath%\hostline.txt \\%%i\C$\WINDOWS\system32\drivers\etc\hosts /y

devices.txt is a text file with your machine names:

machinename1
machinename2

hostline.txt is a text file containing per example:

127.0.0.1 localhost
Eric V.