Link to home
Start Free TrialLog in
Avatar of sivark14
sivark14Flag for India

asked on

Copying host file from remote computers

Hi, I want to collect all server host files and store in the share folder patch with the name of servername. I tried with the below vbscript method for just single computer and it's not working as expected. Can anyone please help me to complete.

If I use localcomputer (.) , it 's working  but not working with remote computer ip's.

Const intForReading = 1
strInputFile = "C:\servers.txt"
Set fso = Wscript.CreateObject("Scripting.FilesystemObject")
Set objInputFile = fso.OpenTextFile(strInputFile, intForReading, False)
While Not objInputFile.AtEndOfStream
strComputer = objInputFile.ReadLine
Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFiles = _
    objWMIService.ExecQuery("Select * From CIM_DataFile Where Name = 'c:\\WINDOWS\\system32\\drivers\\etc\\hosts'")
For Each objFile in colFiles
objFile.Copy ("c:\temp\hosts")
Next
Wend
objInputFile.Close
Avatar of skullnobrains
skullnobrains

you'll need administrative privileges on the remote computer
can you access the $ADMIN and $C shares ?

if you do have access to these shares, it is likely simple to do re copy of
\\COMPUTER\C$\....

there should be an error message. it will be difficult to help you without
Avatar of sivark14

ASKER

Yes, I have admin privilege on remote computer and am able to access $Admin and C$. I haven't received any error msg.
then forget about WMI and read directly the file from
\\COMPUTER_NAME\C$\\WINDOWS\\system32\\drivers\\etc\\hosts

i'm unsure what you want to do with the file's contents so it will be difficult to be more precise
Most of the servers got afftected by virus and some entries have been updated in host file. So we have to check all server host file and do the necessary steps for the affected servers. So we need to collect server list which have been affected by virus. I can get the file manually using admin share If i have less number of servers. But we have more than 500 servers for which I am looking some script solution.
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial