JSI Tip 10211. How can a script list the membership of a local group?

Jerold Schulman

February 28, 2006

1 Min Read
ITPro Today logo in a gray background | ITPro Today


I have scripted LocalGroupMembers.vbs to list the membership of a specified local group.

The syntax for using LocalGroupMembers.vbs is:

cscript //nologo FolderLocalGroupMembers.vbs GroupName

Where GroupName is the local group you wish to enumerate.

Partial Output if GroupName is Administrators

"Administrator"
"NT AUTHORITYNETWORK SERVICE"
"JSIINCDomain Admins"

NOTE: See How can I list the members of a domain group, security or distribution, given the group sAMAccountName (SAMID)?
NOTE: See How can I list the members of a domain group, security or distribution, given the group distinguished name?

LocalGroupMembers.vbs contains:

Dim array, objArguments, strGroupSet objArguments = Wscript.ArgumentsIf WScript.Arguments.Count = 0 then   Wscript.Echo "Syntax: cscript //nologo LocalGroupMembers.vbs GroupName"   Wscript.QuitEnd IfstrGroup = objArguments(0)Set objNetwork = CreateObject("WScript.Network")strComputer = objNetwork.ComputerNameSet objGroup = GetObject("WinNT://" & strComputer & "/" & strGroup & ",group")For Each objMember In objGroup.Members  array = Split(objMember.Parent,"/")  If UCASE(array(Ubound(array))) = UCASE(strComputer) Then     WScript.Echo 

" & objMember.Name &

"  else     WScript.Echo 

" & array(Ubound(array)) & "" & objMember.Name &

"  End IfNext



Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like