'Script to Remote Copy files in list of servers from (computers.txt) file 
'Author: Felipe Ferreira
'Version: 1.0
'Date: 29/10/08

'Todo:


Dim objTSIn,strComputer,strPassword,domain,hostsfile,objPassword
Dim mapcmd,cpcmdf
Dim copyfile, copyto
Dim verbose : verbose = 0  
Dim strScriptFile : strScriptFile = WScript.ScriptFullname
Dim sPath : sPath = Left(strScriptFile, Len(strScriptFile) - Len(WScript.Scriptname)) 'PATH OF SCRIPT LOCATION
Dim objFSO : Set objFSO = CreateObject("Scripting.FilesyStemObject")  


'@@@@@@@@@@@@@@@@@@@@@@ EDIT HERE @@@@@@@@@@@@@@@@@@@@@@@@@@
verbose = 1  						       'Display Outputs
hostsfile = spath & "computers.txt"			       'computers.txt should have hostanmes, or IPs (one per line)
copyfile = spath & "check_emailers.vbs"
copyto = "o:\nrpe_nt\plugins\v2\"

'@@@@@@@@@@@@@@@@@@@@@@ MAIN @@@@@@@@@@@@@@@@@@@@@@@@@@
'Prompt for password and store in encrpyt vbs way

Set objPassword = CreateObject("ScriptPW.Password") 
WScript.StdOut.Write "Please enter your password:" 
strPassword = objPassword.GetPassword() 


'get hosts from file
Set objTSIn = objFSO.OpenTextFile(hostsfile)

Do Until objTSIn.AtEndOfStream
    'Deploy script to remote computer
    strComputer = objTSIn.ReadLine
    pt strComputer & ": " & Now
    execRemote(strComputer)	
    pt strComputer & " Completed at " & Now
    pt ""
    'Set WshShell = Nothing
Loop
objTSIn.Close
pt "Script done."
pt "_______________________________________"

Function execRemote(strcomputerp)
	Dim WshShell,strSCommandPre,strSCommand
	Set WshShell = CreateObject("WScript.Shell")
'Get ComputerName last 3 digits and sets DOMAIN (
	domain = "DIBAJ" & right(strcomputerp,3)	
	WshShell.Run "net use O: /delete /yes" 
'WAITS 3 sec
	wscript.sleep 3000
	mapcmd = "net use o: \\"& strcomputerp & "\c$ /user:" &domain& "\administrator "& strPassword		
	pt "_________________________________________________"
	pt "Mapping Remote o: Drive in " & strcomputerp
	pt mapcmd		
	WshShell.Run mapcmd
'WAIT 20 sec	
	wscript.sleep 20000
'COPY FILE(S)
	pt "_________________________________________________"
    	pt "Coping files " & copyfile & " to " & strcomputerp & " "& copyto
	cpcmdf = "cmd /C copy /Y " & copyfile  & " " &  copyto
	pt cpcmdf
	WshShell.Run cpcmdf	
'WAIT 35 sec	
	wscript.sleep 35000	
	pt "_________________________________________________"
	pt "Disconnect the Remote Disk of: " & strComputerp  	 	
	pt "net use o: /delete /yes"
	WshShell.run "net use O: /delete /yes"
end Function

Function pt(msg)
'PRINTS OUT TO PROMPT
on error resume next
	if verbose = 1 then
	 wscript.echo msg
	end if
end function
