Solved

Using script to manage host file

Posted on 2012-03-23
3
663 Views
Last Modified: 2012-03-23
I need a script that I can run to append to add multiple entries to the host files on my network.

The current script I use is

REM Appendhost.bat
echo 192.168.30.1 server1 >> %SYSTEMDRIVE%\Windows\System32\Drivers\Etc\Hosts
echo 192.168.35.2 server2 >> %SYSTEMDRIVE%\Windows\System32\Drivers\Etc\Hosts
echo 192.168.40.3 server3 >> %SYSTEMDRIVE%\Windows\System32\Drivers\Etc\Hosts

Open in new window


Up until we started using windows 7 this script functioned. After we updated to windows 7 however anytime this is run it appears to overwrite the entire file and only leave a blank file with the entry
192.168.40.3 server3

Entries 1 & 2 do not appear
0
Comment
Question by:itguy565
3 Comments
 
LVL 17

Assisted Solution

by:bigeven2002
bigeven2002 earned 250 total points
ID: 37758302
Hello,

Not sure how to fix the script above, but you can try the PowerShell method alternatively:

http://gallery.technet.microsoft.com/scriptcenter/51ea84d2-717f-467a-8153-cf9bd02573ff
0
 
LVL 53

Accepted Solution

by:
Bill Prew earned 250 total points
ID: 37758325
As long as you are using >> rather than > I don't see any reason why you would get the results you mentioned.

Try copying the hosts file to a different location, say c:\temp, then adjust the BAT script to reference that directory, and see if you have the same problem when you run it.

~bp
0
 
LVL 11

Author Comment

by:itguy565
ID: 37759245
Experts,

I was able to figure out what the issue was with my script. My problem was not with my script above. It works fine as long as you run it locally on each machine. When you attempt to push the same script out using our Kaseya managed service platform it appears that the >> was being treated as > and was causing our script to overwrite the files rather than append.

Thanks for your assistance and quick replies.
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Bash Script to Analyze Oracle Schemas 11 102
cisco switch POE watt limitation 5 75
Problem to With line 4 56
Attention Please 10 40
Hello All, I have been training on Multicast for a while now and whenever I start the topic , I find out that my friends /  Colleagues mention that they do not know how to test Multicast Joins. As most of the multicast would be video traffic and …
This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now