List members of all local groups on a list of computers vbs script

2012/12/12 | By | Reply More

Here is a script that I use to list members of all local groups on a list of computers. It takes a list of computer names and checks the group members on each one then writes the results to a second file. Change the file paths in lines 6,19 and 36 to match your environment. When its complete it will open the text file with the enumerated computers.

Const ForAppending = 8
Const ForReading = 1
ServerCount = 0
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile _
    ("c:\scripts\serverlist.txt", ForReading)
Do Until objTextFile.AtEndOfStream
    strNextLine = objTextFile.Readline
 strComputer = strNextLine
 'WScript.Echo "Processing " & strComputer
 ServerCount = ServerCount + 1
'WScript.Echo "Computers Processed  " & ServerCount

Sub ProcessGroups
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.OpenTextFile("c:\scripts\GroupInfo.txt", _
    ForAppending, True)

objLogFile.writeline " "
objLogFile.writeline "***************** " & strComputer & " *****************"
Set colGroups = GetObject("WinNT://" & strComputer & "")
colGroups.Filter = Array("group")
For Each objGroup In colGroups
    objLogFile.writeline objGroup.Name
    For Each objUser in objGroup.Members
        objLogFile.writeline vbTab & objUser.Name
End Sub

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "C:\scripts\GroupInfo.txt"

Category: VBS

Leave a Reply

%d bloggers like this: