Updating windows hosts file

Example usage: .\Update Multiple Hosts Files.ps1 -Server List @("","","") -Timeout 7 I'm going to copy the local hosts file to 3 servers Couldn't access file at \\C$\Windows\System32\drivers\etc\hosts New hosts file written to \\C$\Windows\System32\drivers\etc\hosts Couldn't access file at \\C$\Windows\System32\drivers\etc\hosts Done!

PS C:\ Conclusion There are various reasons (not all of them nefarious) why you might want to edit your Windows hosts file to change the routing of certain domains.

I’ll first document how to find the damn file, and then go through a bunch of options on what to check and how to fix different possible issues.

These scripts are a safe, easy way to do that, especially in the case where you need to update multiple machines at the same time.

A little while ago, I used a somewhat less-sophisticated version of these scripts in real life to fix a major problem.

Summary In this article I present a couple of simple Power Shell scripts which will modify the hosts file on one (or more) Windows machines, so that you can route traffic destined for certain domains to specific IP addresses with minimal fuss.

The scripts do this by adding (or removing) entries to (or from) the hosts file and they do this idempotently, so you don't need to write any checks when adding or removing.

It can allow you to check, what a domain will show if it’s pointed to a different server.

The hosts file will be edited to block certain hostnames (like advertising/malicious hosts), or used for web development purposes, i.e. To access the hosts file in Windows XP, Vista, 7, 8x, 10 you have to use the following command in the Run Line to open the file with notepad. STEP 2: Copy the below mentioned command and paste into the Run Line.

If you copied and pasted hosts entries from somewhere, you may end up with multiple spaces.

In theory, the file supports multiple spaces separating the two columns, but it’s another thing to try if nothing else works.

To be on the safe side, make sure all lines in your hosts file either use tabs or spaces, not both. There is a registry key specifying the location of the hosts file.

Tags: , ,