Link to home
Start Free TrialLog in
Avatar of vitaminC_ny
vitaminC_ny

asked on

Enumerate Local Admin group members using Text Files as Host name source

Hi all,
 I have a Script that generates the host names of domain servers into a file called servers.txt using the following format:

server1
server2
server3
etc.

I want to  read that text file  and for each hsotname in it I want to enumerate the members of the local admins group for that server  . I also want the Server name to be listed with each local admin group. I havent even been able to come close to getting this to work correctly as of yet and I am running out of time. Can someone  offer me any assistance on this please? Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Shift-3
Shift-3
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RobSampson
Hi, I haven't tested this yet, but give this a shot.

Regards,

Rob.
'On Error Resume Next
Const intForReading = 1
' Variable for admin group name, modify this
' variable if the administrators account has
' been renamed.
strAdminGroup = "Administrators"
' Output file name and path
strLogFile = "adminaccounts.csv"
strInputFile = "computers.txt"
 
'Create Log File
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.CreateTextFile(strLogFile, True)
 
Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)
 
objLogFile.Write """Computer"",""Members"""
 
' Output domain computer accounts, connect to each
' computer, and enumerate admin account members
While Not objInputFile.AtEndOfStream
	strComputer = objInputFile.ReadLine
	objLogFile.Write VbCrLf & """" & strComputer & ""","
	Set objGroup = GetObject("WinNT://" & strComputer & "/" & strAdminGroup)
	If Err.Number <> 0 Then
		objLogFile.Write """*** System Unreachable ***"""
		Err.Clear
	Else
		strMembers = ""
		For Each member In objGroup.Members
			If strMembers = "" Then
				strMembers = member.Name
			Else
				strMembers = strMembers & ";" & member.Name
			End If
		Next
		objLogFile.Write """" & strMembers & """"
	End If
Wend
 
objLogFile.Close
objInputFile.Close
 
' All done!
WScript.Echo "Done."

Open in new window

Avatar of vitaminC_ny
vitaminC_ny

ASKER

Although I was looking for a VB solution this option worked the best for me. Thanks!!!