×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

How to: List members of the "Local Administrator Group

How to: List members of the "Local Administrator Group

How to: List members of the "Local Administrator Group

(OP)
I have a script that ping the wks in a particular OU and put them into a .txt file if successful.  I have called up the successful.txt file and put it into an array.  I then want to use that array of wks names to list all members of the local admin group.  

If someone has a suggestion it would be greatly appreciated.

thanks,
Jaws

RE: How to: List members of the "Local Administrator Group

Hello Jaws25,

Which part poses a difficulty? or just want to prettier presentation writing to excel or whatever?

Run the loop with each element of the array within which stores the computer's netbios name. With the computer name, bind to the (local) administrators group "WinNT://computername/administrators,group" and then use the .members collection to retrieve all members' objects. Their .name will give you their login samaccountname.

regards - tsuji

RE: How to: List members of the "Local Administrator Group

(OP)
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 = fso.OpenTextFile(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

RE: How to: List members of the "Local Administrator Group

Jaw25,

First a revision of pingSystems.

CODE

'================
'= Ping Systems =
'================
Sub PingSystems()
Dim Outputfile, FSO, OFile, Outputfile2, oFile2
Dim iFile, objContainer, StdOut, objShell    
    
    OutputFile="C:\share\ad\pingSuccessful.txt"
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Set oFile = FSO.CreateTextFile(OutputFile, True)
    OutputFile2="C:\share\ad\pingFailed.txt"
    Set oFile2 = FSO.CreateTextFile(OutputFile2, True)
    
    InputFile="c:\share\ad\container.txt" 'contains OU structure
    
    Set iFile = FSO.OpenTextFile(InputFile, 1, true)  'assume existing else create an empty file
    
    WScript.Echo "Pinging Systems Now..."
    Do until iFile.AtEndOfStream
    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)
      do while objScriptExec.status=0
          wscript.sleep 100
      loop
      strPingResults = LCase(objScriptExec.StdOut.ReadAll)
      If InStr(strPingResults, "reply from")<>0 Then
        oFile.WriteLine(Computer)
      Else
       oFile2.WriteLine(Computer)
      End If
    Next
    Loop
    iFile.close
    oFile2.close
    oFile.close

    WScript.Echo "Pinging Systems Complete!"
End Sub
Your instr() is doing the opposite you are intended to do.

Try the revision first and feedback.

- tsuji

RE: How to: List members of the "Local Administrator Group

Correction:

Maybe not the opposition! So I take back that line.

- tsuji

RE: How to: List members of the "Local Administrator Group

Jaw25,

Here a revision for the rest.

CODE

'========================
'= 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 = fso.OpenTextFile(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
   if not isempty(Computer) then
      GetLocalAdmins Computer 'calls sub to get local admin info - pass computer as variable explicitly
   end if
Wend
f.Close
End Sub

'=====================
'= Gets Local Admins =
'=====================
Sub GetLocalAdmins (Computer)
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
I would prefer to pass computer as variable explicitly to avoid problem with such a common name and enforce its limited scope. Also, check computer not being empty before passing just in case of empty line.

- tsuji

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close