Solved

Hosts file update with 2 records remotely.

Posted on 2011-09-18
2
415 Views
Last Modified: 2012-05-12
Hi,
Hosts file update with 2 records remotely.
I want help with a script that reads a txt file with machine names and updates all machines hosts file with 2 entries and then gives Success and failure report.

Regards
Raja
0
Comment
Question by:bsharath
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 18

Accepted Solution

by:
x-men earned 500 total points
ID: 36559218
'filename is expected to have one
'name per line
On Error Resume Next
Dim strFilename,strReportFile ,HostsLine1,HostsLine2,objShell, strExecutable, objFSO, objTS, Computer
strFilename = "c:\Computers.txt"
strReportFile = "C:\report.txt"
HostsLine1 = "IP.IP.IP.IP      Name"
HostsLine2 = "IP.IP.IP.IP      Name"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTS = objFSO.OpenTextFile(strFilename)
Set objReport = objFSO.OpenTextFile(strReportFile, 8,True)

Do Until objTS.AtEndOfStream
      Computer = objTS.ReadLine
      objReport.Write Computer
      Set objHostsFile = objFSO.OpentextFile("\\"&Computer&"\c$\windows\system32\drivers\etc\hosts", 8)
            objReport.Write vbTab & Err.Number & vbTab & Err.Description
      objHostsFile.WriteLine HostsLine1
      objHostsFile.WriteLine HostsLine2
            objReport.WriteLine  vbTab & Err.Number & vbTab & Err.Description
      objHostsFile.Close
Loop
objTS.Close
objReport.Close


0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36561218
"updates all machines hosts file with 2 entries"

Do you mean adding 2 entries, or changing 2 entries?

Cheers
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

623 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