Is it possible using VBA to identify the members of a group?
Example: A selected folder’s security tab properties lists a group for rights/permissions. I am trying to identify who the individuals are in a group.
Thanks,
John
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » Identify Members of a Group (03)
Depending on your configuration, something like this may work for you:
Function ListMembers(strDomainName As String, strGroupName As String) Dim objGroup, objMember As Object Set objGroup = GetObject("WinNT://" & strDomainName & "/" & strGroupName & ",group") For Each objMember In objGroup.Members Debug.Print objMember.Name Next objMember End Function
HTH
What other objMember definitions are available to the members? I know that one can obtain objMember.Name and objMember.FullName.
If you add a Stop statement after instantiating the object (e.g., just inside the For Each loop) and open the Locals window, you may be able to browse the object’s properties and gain more insight. Any luck?
This should give some idea. Not all properties are always available:
Function ListMembers(strDomainName As String, strGroupName As String) Dim objGroup, objMember As IADsUser Set objGroup = GetObject("WinNT://" & strDomainName & "/" & strGroupName & ",group") For Each objMember In objGroup.Members With objMember Debug.Print .AccountDisabled Debug.Print .AccountExpirationDate Debug.Print .ADsPath Debug.Print .BadLoginAddress Debug.Print .BadLoginCount Debug.Print .Class Debug.Print .Department Debug.Print .Description Debug.Print .Division Debug.Print .EmailAddress Debug.Print .EmployeeID Debug.Print .FaxNumber Debug.Print .FirstName Debug.Print .FullName Debug.Print .GraceLoginsAllowed Debug.Print .GraceLoginsRemaining Debug.Print .GUID Debug.Print .HomeDirectory Debug.Print .HomePage Debug.Print .IsAccountLocked Debug.Print .Languages Debug.Print .LastFailedLogin Debug.Print .LastLogin Debug.Print .LastLogoff Debug.Print .LastName Debug.Print .LoginHours Debug.Print .LoginScript Debug.Print .LoginWorkstations Debug.Print .Manager Debug.Print .MaxLogins Debug.Print .MaxStorage Debug.Print .Name Debug.Print .NamePrefix Debug.Print .NameSuffix Debug.Print .OfficeLocations Debug.Print .OtherName Debug.Print .Parent Debug.Print .PasswordExpirationDate Debug.Print .PasswordLastChanged Debug.Print .PasswordMinimumLength Debug.Print .PasswordRequired Debug.Print .Picture Debug.Print .PostalAddresses Debug.Print .PostalCodes Debug.Print .Profile Debug.Print .RequireUniquePassword Debug.Print .Schema Debug.Print .SeeAlso Debug.Print .TelephoneHome Debug.Print .TelephoneMobile Debug.Print .TelephoneNumber Debug.Print .TelephonePager Debug.Print .Title End With Next objMember End Function
Rory,
Taking this one step further, I created an array of the 53 properties and would like to pass each of the 53 properties to the “Debug.Print” line.
My code looks like this:
[codebox]Function ListMembers(strDomainName As String, strGroupName As String)
Dim objGroup, objMember As Object
Dim myArray
Set objGroup = GetObject(“WinNT://” & strDomainName & “/” & strGroupName & “,group”)
myArray = Array(“FullName”, “Name”) ‘Kept the 53 properties to two for testing purposes
For Each objMember In objGroup.Members
With objMember
Debug.Print objMember.FullName ‘This Line works without variable from array being passed through
Debug.Print objMember & “.” & myArray(1) ‘This is where I get hung up
End With
Next objMember
[/codebox]
‘more code follows…
Thanks for your assistance,
John
You’ll need to use CallByName
[codebox]Function ListMembers(strDomainName As String, strGroupName As String)
Dim objGroup, objMember As Object
Dim myArray
Set objGroup = GetObject(“WinNT://” & strDomainName & “/” & strGroupName & “,group”)
myArray = Array(“FullName”, “Name”) ‘Kept the 53 properties to two for testing purposes
For Each objMember In objGroup.Members
With objMember
Debug.Print CallByName(objMember, myArray(1), VbGet)
End With
Next objMember
[/codebox]
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.