Solved

Using script to manage host file

Posted on 2012-03-23
3
662 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 52

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Every server (virtual or physical) needs a console: and the console can be provided through hardware directly connected, software for remote connections, local connections, through a KVM, etc. This document explains the different types of consol…
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…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 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

18 Experts available now in Live!

Get 1:1 Help Now