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


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

The syntax for using LocalGroupMembers.vbs is:

cscript //nologo <Drive:>\Folder\LocalGroupMembers.vbs GroupName

Where GroupName is the local group you wish to enumerate.

Partial Output if GroupName is Administrators

"Administrator"
"NT AUTHORITY\NETWORK SERVICE"
"JSIINC\Domain 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, strGroup
Set objArguments = Wscript.Arguments
If WScript.Arguments.Count = 0 then
   Wscript.Echo "Syntax: cscript //nologo LocalGroupMembers.vbs GroupName"
   Wscript.Quit
End If
strGroup = objArguments(0)
Set objNetwork = CreateObject("WScript.Network")
strComputer = objNetwork.ComputerName
Set 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 If Next



Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish