Here is the script that I have been working on below. It pings systems based off of the container.txt file OU list(I chose one with only a few systems to save time). Successful pings are logged to pingsuccessful.txt and then loaded into an array. When loading the systems names into the array each system is check for members of the local administrators group. For some reason it errors out when trying to get the members off the second system. Error message is:
C:\Share\AD\admins.vbs(86, 1) (null): The network path was not found.
Any help would be greatly appreciated. Thanks!!!!
'========
'= Main =
'========
Dim Computer, elem
PingSystems
MakeArray
MsgBox "Listing Local Admins is now complete"
'================
'= Ping Systems =
'================
Sub PingSystems()
Dim Outputfile, oFSO, OFile, Outputfile2, oFSO2, oFile2
Dim iFSO, iFile, objContainer, StdOut, objShell
OutputFile="C:\share\ad\pingSuccessful.txt"
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFile = oFSo.CreateTextFile(OutputFile, True)
OutputFile2="C:\share\ad\pingFailed.txt"
Set oFSO2 = CreateObject("Scripting.FileSystemObject")
Set oFile2 = oFSO.CreateTextFile(OutputFile2, True)
Set iFSO = CreateObject("Scripting.FilesyStemObject")
InputFile="c:\share\ad\container.txt" 'contains OU structure
Set ifile = iFSO.OpenTextFile(inputfile)
WScript.Echo "Pinging Systems Now..."
Do until ifile.AtEndOfLine
strComputerContainer = ifile.ReadLine
Set objContainer = GetObject("LDAP://" & strComputerContainer)
objContainer.Filter = Array("Computer")
Set StdOut = WScript.StdOut
Set objShell = CreateObject("WScript.Shell")
On Error Resume Next
For Each objComputer In objContainer
Computer = Split(objComputer.Name, "=")(1)
Set objScriptExec = objShell.Exec("ping -n 2 -w 1000 " & Computer)
strPingResults = LCase(objScriptExec.StdOut.ReadAll)
If InStr(strPingResults, "reply from") Then
oFile.WriteLine(Computer)
Else
oFile2.WriteLine(Computer)
End If
Next
Loop
WScript.Echo "Pinging Systems Complete!"
End Sub
'========================
'= Opens TXT into array =
'========================
Sub MakeArray
Const ForReading = 1
Const WKS = "c:\share\ad\pingsuccessful.txt"
Dim fso, f
Dim arrText()
Dim text
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fs

penTextFile(WKS, ForReading)
iUpperBound = 0
While Not f.AtEndOfStream
ReDim Preserve arrText(iUpperBound)
arrText(UBound(arrText)) = f.ReadLine
iUpperBound = iUpperBound + 1
Computer = arrText(UBound(arrText))
WScript.Echo Computer
GetLocalAdmins 'calls sub to get local admin info
Wend
f.Close
End Sub
'=====================
'= Gets Local Admins =
'=====================
Sub GetLocalAdmins
Dim objComp
strComputer = computer
Set objComp = GetObject("WinNT://" & strComputer) 'seems to have issues here.
objComp.GetInfo 'or here....
If objComp.PropertyCount > 0 Then
Set objGroup = GetObject("WinNT://" & strComputer & "/Administrators,group")
If objGroup.PropertyCount > 0 Then
WScript.Echo "The members of the local Administrators group on " & strComputer & " are:"
For Each mem In objGroup.Members
WScript.echo vbTab & Right(mem.adsPath,Len(mem.adsPath) - 8)
Next
Else
WScript.echo "** Connecting to the local Administrators group on " & strComputer & " failed."
WScript.Quit 1
End If
Else
WScript.Echo "** Connecting to " & strComputer & " failed."
WScript.Quit 1
End If
End Sub