New to vbs, loop through servers check local admin account

Hi guys, i do my scripting mostly in powershell, looking to do this project in vbs since a lot of servers don't allow remoting. I have a file with host names, i want to read each server, ping, if pingable, use local admin credentials, if successful write to one log file, if failed write to another log file. This is what i have so far:

Dim fso, file, fileLine
 
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.OpenTextFile("C:\Users\mkond\Desktop\hosts.txt")
Set WshShell = CreateObject("WScript.Shell")
strUser = "mmhs\Administrator"
strPass = "pass"
do while not file.AtEndOfStream
    strServer =  file.ReadLine()
    PINGFlag = Not CBool(WshShell.run("ping -n 1 " & strServer,0,True))
      	If PINGFlag = True Then
  	WScript.Echo strServer & " responded to ping."
  	Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objSWbemServices = objSWbemLocator.ConnectServer _
    (strServer, "root\cimv2", strUser, strPass)
	objSWbemServices.Security_.ImpersonationLevel = 3
		Else
  	WScript.Echo strServer & " did not respond to ping."
		End If

Loop

any help appreciated


  • Edited by ImMax 15 hours 8 minutes ago
August 19th, 2015 12:07pm

What is the question?

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 12:26pm

one is how do i know if remote was successful then other piece is can i make it a bit faster? the remoting can take 2 seconds or so.
August 19th, 2015 12:39pm

If there is an error it is not successful.

You cannot make it faster.  Fix network.  Fix servers.  New hardware.  Faster processor.

You are running a very bad ping.  Use Win32_PinStatus as it is much faster.

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 12:46pm

May i ask why its not creating my log files and writing to them with below code?

On Error Resume Next 

Dim fso, file, fileLine

Set fso = CreateObject("Scripting.FileSystemObject")
Set myErrorLog = objFSO.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Error.log", ForAppending, True)
Set myGoodLog = objFSO.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Good.log", ForAppending, True)
Set myPingLog = objFSO.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Ping.log", ForAppending, True)
Set file = fso.OpenTextFile("C:\Users\mkond\Desktop\testcreds\hosts.txt")
Set WshShell = CreateObject("WScript.Shell")
strUser = "domain\mkond"
strPass = "pass"
do while not file.AtEndOfStream
    strServer =  file.ReadLine()
    PINGFlag = Not CBool(WshShell.run("ping -n 1 " & strServer,0,True))
      	If PINGFlag = True Then
  	WScript.Echo strServer & " responded to ping."
  	Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
	Set objSWbemServices = objSWbemLocator.ConnectServer _
    (strServer, "root\cimv2", strUser, strPass)
	objSWbemServices.Security_.ImpersonationLevel = 3
  	myGoodLog.WriteLine strServer
		Else
  	WScript.Echo strServer & " did not respond to ping."
  	myPingLog.LogError "Server" &strServer & " did not respond to ping."
		End If

Loop


  • Edited by ImMax 11 hours 12 minutes ago
August 19th, 2015 1:07pm

You changed the script and the question.

Remove this line: On Error Resume Next

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 1:26pm

I am getting an invalid procedure call or procedure in these lines

Set objfso = CreateObject("Scripting.FileSystemObject")
Set myErrorLog = objfso.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Error.log", ForAppending, True)
Set myGoodLog = objfso.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Good.log", ForAppending, True)
Set myPingLog = objfso.OpenTextFile("C:\Users\mkond\Desktop\testcreds\Ping.log", ForAppending, True)

createfile works but i am under impression since i set these to true, it would create them if files dont exist already

August 19th, 2015 4:00pm

What is this? "ForAppending"

It appears to be nothing.

Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 4:06pm

oh i see i need to use value 8, thanks

back to the catching servers that return access denied when i try to remote to them, how can i check that it failed - i am thinking based on the error message

August 19th, 2015 4:15pm

Start here: https://technet.microsoft.com/library/ee176982.aspx
Free Windows Admin Tool Kit Click here and download it now
August 19th, 2015 4:17pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics