Re: help with this script



You assign a value to strComputer outside of your loop, and never alter it.
As a result, you connect to the same computer repeatedly when you bind to
the local Administrator user. I see no reason to read the file into a
dictionary object. You loop through the file, then loop again through the
dictionary object. I would try (not tested):
==================
' Start

Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const Data_Path = "C:\"
' Path to your log file e.g C:\ping.txt or .csv
Const fileName = "ping.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
' Path to your file containing IP addresses
Set objTextFile = objFSO.OpenTextFile("c:\Scripts\servers.txt", 1)

' Logging
Set fso = CreateObject("Scripting.FileSystemObject")

' If log file does not exist
' Create the file and write to it
' If the file does exist then just append to the log file
If Not FSO.FileExists(Data_Path & filename) Then
Set f = fso.OpenTextFile(Data_Path & fileName,2, True)
Else
Set f = fso.OpenTextFile(Data_Path & fileName,8)
End If

' Bind to the WMI Service once, rather than repeatedly.
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")

' Read each line of file containing the IP addresses
Do Until objTextFile.AtEndOfStream
' Remove leading and trailing blanks.
strComputer = Trim(objTextFile.Readline)
' Skip blank lines.
If (strComputer <> "") Then
' Ping this computer.
Set colItems = objWMIService.ExecQuery _
("Select * from Win32_PingStatus " & _
"Where Address = '" & strComputer & "'")
For Each ipItem In colItems
If ipItem.StatusCode = 0 Then
' WScript.Echo strComputer & " responded."
' If responded write to log file
f.WriteLine VbCrLf & strComputer & " responded."

Set objUser = GetObject("WinNT://" _
& strComputer & "/Administrator, user")

objUser.SetPassword "NewPass"
objUser.SetInfo

Else
' WScript.Echo strComputer & " did not respond."
' If did not respond write to log file
f.WriteLine VbCrLf & strComputer & " did not respond."
End If
Next
End If
Loop


Wscript.Echo "Script ended. review the results in file" _
& Data_Path & fileName
' Close the Text file containing the ip addresses
objTextFile.Close

' End

--
Richard
Microsoft MVP Scripting and ADSI
Hilltop Lab web site - http://www.rlmueller.net
--

"Avi G" <AviG@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:BC05EF0D-067C-44D1-A7B4-D04B532BD229@xxxxxxxxxxxxxxxx
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





.



Relevant Pages

  • Re: password change
    ... Dim objRootDSE, strDNSDomain, strQuery, adoRecordset, strComputer ... ' Open the log file for write access. ... is not reset to a separate text file of "missed" computers. ...
    (microsoft.public.windows.server.general)
  • Re: HELP! Shutdown / ping script
    ... Dim objFSO, objTS, strComputer ... >I want to continue using PSShutdown for now. ... >Const OpenAsASCII = 0 ...
    (microsoft.public.scripting.vbscript)
  • Re: IP Config data
    ... >I want to put an array of computers insted of strcomputer. ... You could create an array of hard coded computer names, ... Const OpenAsDefault = -2 ... Set objFile = objFSO.OpenTextFile(strTempFile, ForReading, _ ...
    (microsoft.public.scripting.vbscript)
  • Re: Return computer name
    ... Dim strComputer, strUsername, objWMI, colUsers, objUser ... This only enumerates active sessions on the one computer. ... computer name to a shared log file. ...
    (microsoft.public.scripting.vbscript)
  • Re: Return computer name
    ... Dim strComputer, strUsername, objWMI, colUsers, objUser ... This only enumerates active sessions on the one computer. ... name to a shared log file. ... MVP Directory Services ...
    (microsoft.public.scripting.vbscript)