1

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.

8 Answers 8

12

I realize the question is about modifying the host file via vbscript.

Would it be more effective to create a new internal DNS entry for the hostname you're trying to resolve? If you truly want EVERY user/machine on the network to see this change, perhaps this would be easier?

4
  • that's a good idea. How do I do that on windows server 2003?
    – user20192
    Sep 14, 2009 at 18:08
  • Just have to make sure that you would have some sort of sanity checking. I usually want to account for the systems having the change made afterwords.
    – breadly
    Sep 14, 2009 at 18:10
  • 3
    "How do I do that on windows server 2003" - that's a bit of a "plz send teh codes". You will need to plan and research it. It's not just as simple as installing the DNS and off you go, but it's likely to be a simpler, better and easier to maintain solution than editing dozens of hosts files. Sep 14, 2009 at 21:44
  • IF you have a Windows domain that is newer than NT4 then you already have to have DNS, it's a fundamental part of an Active Directory Domain. There are very few legitimate reasons for taking the host file route when you already have a DNS infrastructure that you control.
    – Helvick
    Sep 14, 2009 at 23:35
4

If you've got a domain, simply use the login script (group policy object) method others suggest and tell everyone to reboot.

Better: add the entry to your local DNS server instead.

Failing that, VBScript still isn't required. Consider a batch file with lines like this:

echo 10.20.30.40 fishsticks >> \\hostname\c$\windows\system32\drivers\etc\hosts

An aside: You don't sound organized.

It isn't the problem you asked about, but it's the problem you really should be fixing first.

Get a spreadsheet out and count the machines if you have to.

3

Don't use "HOSTS" files. Period. Any "solution" that users HOSTS files is just creating a new problem.

I presume you've got an Active Directory domain. Fire up the "DNS Management" management console on a domain controller (which, odds are, is also one of your DNS servers), open the server node, the "Forward Lookup Zones" node, and highlight the zone that corresponds to your Active Directory domain. Click "Action" (in the menu) and "New Host". Enter the hostname and IP address of the new host.

Within 5 minutes the clients of that DNS server will be able to resolve that hostname.

Presumably you're a sysadmin. It sounds like you need to spend some time learning about DNS, because it will save you a lot of headaches in the future.

1

Puppet is a configuration management solution that says it supports windows :)

0

Short of a tool like SCCM you are not going to be able to discover an exact listing of machines on the network.

First task will be finding the hosts:

  1. If you can use a startup script in a GPO this is easy

  2. If not, then if you are not too skillful with scripting, I would do a laymans approach. First use a tool like angryIP to get a listing of all of the windows desktops you want to modify the tool with

Then...

  1. If you have the GPO, I would just write a batch file that has something like echo 192.168.0.2 hostname > %systemroot%\system32\drivers\etc\hosts.

  2. If you don't have a GPO, look at PStools (specifically PSexec). Copy the hostnames discovered with angryIP into a hostfile and then use psexec to run the command with the hostname file as the array it would look something like this psexec @hostfile "echo 192.168.0.2 hostname > %systemroot%\system32\drivers\etc\hosts"

0

Maybe, it's time to setup local DNS there? :)

0

Agreed at the recommendation to look at DNS, but let's not forget that there might be some horrible old legacy apps that still require hosts name resolution on this network.

0

If you are using a gateway server then modify the hosts there and all is well. Other wise if your Router(cisco/juniper) allow for a text version of the hosts file put it there. That will circumvent having to put a host file on every client.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .