Re: help with this script
- From: "Richard Mueller [MVP]" <rlmueller-NOSPAM@xxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 5 Feb 2007 11:47:04 -0600
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,write
i've this script that take ip's from text file do ping to every ip and
the results into ping.csv then change the local admin password to each ip.ip's
now my problem is that the change local password isn't do loop for all
in the text file only for the first one i know that i write somethingwrong
but i can't make it work. can you help me with this script that he willwork
and even improve it???to
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
your file containing IP addressesexist
'Logging
Set fso = CreateObject("Scripting.FileSystemObject")
If Not FSO.FileExists(Data_Path & filename) Then 'If log file does not
Set f = fso.OpenTextFile(Data_Path & fileName,2, True) 'Create the fileand
write to itthen
Else
Set f = fso.OpenTextFile(Data_Path & fileName,8)'If the file does exist
just append to the log file"/Administrator,
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 &
user")fileName
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 &
objTextFile.Close 'Close the Text file containing the ip addresses
objDictionary.RemoveAll
'End
.
- Follow-Ups:
- Re: help with this script
- From: Avi G
- Re: help with this script
- References:
- help with this script
- From: Avi G
- help with this script
- Prev by Date: Re: Poll AD Accounts set to "never expire"
- Next by Date: Re: Poll AD Accounts set to "never expire"
- Previous by thread: help with this script
- Next by thread: Re: help with this script
- Index(es):
Relevant Pages
|