Remove Hosts file entries

I need a script to remove about 100 entries from an existing Hosts file from Windows XP PC's. The IP addresses are changing and DNS will now be provided via our Win2k3 server. I know I cannot use a wildcard in Hosts files, so what do you recommend. We cannot replace the Hosts file because there are other entries that are not in DNS yet. Thanks for your help.

Who is Participating?

This simple tool removes lines that include matching strings from a file. A single iteration would look like this:
REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
COPY c:\Windows\System32\Drivers\etc\HostsNew. C:\Windows\System32\Drivers\etc\Hosts.

Or, you could do them in pairs:
REMFILE "string to remove" <C:\Windows\System32\Drivers\etc\Hosts. >c:\Windows\System32\Drivers\etc\HostsNew.
REMFILE "second string to remove" <C:\Windows\System32\Drivers\etc\HostsNew. >c:\Windows\System32\Drivers\etc\Hosts.

You can then build a batch file with 100 lines in it to remove all the excess gunk from your HOSTS files.

Honestly, though, I echo the sentiments of the other folks -- leave the hosts file for now and blow it away when you are done. This works as long as they are not changing the IP addresses at the same time.

>> "We cannot replace the Hosts file because there are other entries that are not in DNS yet."

Are these additional entries you need the same on all machines? If so I would say to do the following:

Create a generic hosts file with all these entries and save it.

Create a script (Logon or via GPO) to copy this file over the existing one.

Why not just wait until you have all the entries in DNS and blow away the hosts files? Seems like you are going to have a lot of fun troubleshooting name resolution problems if you are relying on hosts and DNS... JMO

0

603currierAuthor Commented: 2009-04-24

Thanks for the responses. The entity forcing this change is an external one and waiting until DNS is available for all sites is not any option.

0

603currierAuthor Commented: 2009-05-02

They are changing the IP address unfortunately. Thanks you've given me good ifno.