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.
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?
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.
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.
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:
If you can use a startup script in a GPO this is easy
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
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.
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"
Maybe, it's time to setup local DNS there? :)
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.
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.