help with this script
- From: Avi G <AviG@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 5 Feb 2007 04:16:01 -0800
Hi,
i've this script that take ip's from text file do ping to every ip and write
the results into ping.csv then change the local admin password to each ip.
now my problem is that the change local password isn't do loop for all ip's
in the text file only for the first one i know that i write something wrong
but i can't make it work. can you help me with this script that he will work
and even improve it???
here is the script
'Start
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Data_Path = "C:\"
Const fileName = "ping.csv" 'Path to your log file e.g C:\ping.txt or .csv
Set objDictionary = CreateObject("Scripting.Dictionary")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile("c:\Scripts\servers.txt", 1) 'Path to
your file containing IP addresses
'Logging
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then 'If log file does not exist
Set f = fso.OpenTextFile(Data_Path & fileName,2, True) 'Create the file and
write to it
Else
Set f = fso.OpenTextFile(Data_Path & fileName,8)'If the file does exist then
just append to the log file
End If
'Read each line of file containing the IP addresses
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
objDictionary.Add i, strNextLine
i = i + 1
Loop
strComputer = objDictionary(objItem)
'Ping the computers
For Each objItem In objDictionary
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & objDictionary(objItem) & "'")
For Each ipItem In colItems
If ipItem.StatusCode = 0 Then
'WScript.Echo objDictionary(objItem) & " responded."
f.WriteLine VbCrLf & objDictionary(objItem) & " responded." 'If
responded write to log file
Set objUser = GetObject("WinNT://" & strComputer & "/Administrator,
user")
objUser.SetPassword "NewPass"
objUser.SetInfo
Else
'WScript.Echo objDictionary(objItem) & " did not respond."
f.WriteLine VbCrLf & objDictionary(objItem) &" did not respond."
'If did not respond write to log file
End If
Next
Next
Wscript.Echo "Script ended. review the results in file" & Data_Path & fileName
objTextFile.Close 'Close the Text file containing the ip addresses
objDictionary.RemoveAll
'End
.
- Follow-Ups:
- Re: help with this script
- From: Richard Mueller [MVP]
- Re: help with this script
- Prev by Date: Server service check script
- Next by Date: Shell.application verb problem
- Previous by thread: Server service check script
- Next by thread: Re: help with this script
- Index(es):
Relevant Pages
|