Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 423
  • Last Modified:

Hosts file update with 2 records remotely.

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
bsharath
Asked:
bsharath
1 Solution
 
x-menIT super heroCommented:
'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
 
ReneGeCommented:
"updates all machines hosts file with 2 entries"

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

Cheers
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now