Results 1 to 9 of 9
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Identify Members of a Group (03)

    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

  2. #2
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts

    Re: Identify Members of a Group (03)

    Depending on your configuration, something like this may work for you:
    <pre>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
    </pre>


    HTH
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Identify Members of a Group (03)

    Rory,

    Thanks for the code. This is exactly what I was looking for.

    John

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    [quote name='rory' post='568027' date='03-Apr-2006 12:19']For Each objMember In objGroup.Members
    Debug.Print objMember.Name
    Next objMember
    HTH[/quote]

    Rory,

    What other objMember definitions are available to the members? I know that one can obtain objMember.Name and objMember.FullName.

    Thanks,
    John

  5. #5
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts
    [quote name='jstevens' post='792022' date='03-Sep-2009 13:43']What other objMember definitions are available to the members? I know that one can obtain objMember.Name and objMember.FullName.[/quote]
    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?

  6. #6
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    This should give some idea. Not all properties are always available:
    Code:
    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
    Regards,
    Rory

    Microsoft MVP - Excel

  7. #7
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  8. #8
    WS Lounge VIP rory's Avatar
    Join Date
    Dec 2000
    Location
    Burwash, East Sussex, United Kingdom
    Posts
    6,280
    Thanks
    3
    Thanked 191 Times in 177 Posts
    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]
    Regards,
    Rory

    Microsoft MVP - Excel

  9. #9
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Exactly what I was looking for.

    Thanks,
    John

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •