Sign in to follow this  
Followers 0
gcue

getting members from nested upon nested groups

60 posts in this topic

#1 ·  Posted (edited)

i am trying to pull the members of group A. sometimes group A has a nested group B in as a member. this sometimes carries onto several nested groups *bleh*. i am trying to build an array of members and which parent group they belong to.

i am trying to find the most efficient way of doing this... here's what I have so far but this only handles up to 3 nested groups. problem is im finding some groups have more than a few nested groups!

hope this makes sense..

appreciate the help!

For $y = 0 To UBound($members) - 1  ;a list of memebers from Group A
    If $members[$y] = "" Then ContinueLoop

    $member_count += 1

    If StringInStr($members[$y], "@") = 0 And StringInStr($members[$y], "CN=") = 0 Then ;this is how i know if the Group A member is also a group (hence referred to as Group B)

     $members_2 = GetGroup_Members($members[$y]) ;pulls members of nested Group B

     For $z = 0 To UBound($members_2) - 1
      If $members_2[$z] = "" Then ContinueLoop
 
      $member_count += 1
 
      If StringInStr($members_2[$z], "@") = 0 And StringInStr($members_2[$z], "CN=") = 0 Then ;again this is how i know if the Group B member is also a group (hence referred to as Group C)

       $members_3 = GetGroup_Members($members_2[$z]) ;pulls members of nested Group C (member of Group B)
       For $a = 0 To UBound($members_3) - 1
        If $members_3[$a] = "" Then ContinueLoop
        $member_count += 1
        ReDim $contacts[UBound($contacts) + 1][3]
        $contacts[UBound($contacts) - 1][0] = $group_name
        $contacts[UBound($contacts) - 1][1] = $members_3[$a]
        $contacts[UBound($contacts) - 1][2] = "PUBLIC_GROUP"
       Next
      Else
       ReDim $contacts[UBound($contacts) + 1][3]
       $contacts[UBound($contacts) - 1][0] = $group_name
       $contacts[UBound($contacts) - 1][1] = $members_2[$z]
       $contacts[UBound($contacts) - 1][2] = "PUBLIC_GROUP"
      EndIf
     Next
    Else
     ReDim $contacts[UBound($contacts) + 1][3]
     $contacts[UBound($contacts) - 1][0] = $group_name
     $contacts[UBound($contacts) - 1][1] = $members[$y]
     $contacts[UBound($contacts) - 1][2] = "PUBLIC_GROUP"
    EndIf
   Next
Edited by gcue

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

So you want to look for Joe in group1, and if you find him, search in group1's nested group, and if you find him there another nested group? Do you also have to search a group2 with nested groups as well for the same person?

Group 1 (FOUND HIM)
   Nested 1 (FOUND HIM)
      Nested 2 (FOUND HIM)
         Nested 3 (nope...  return Nested 2)
Group 2 ( FOUND HIM)
   Nested 1 (nope... return Group 2)
Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

actually not really looking for someone specific just want to drill down all the nested groups to the point where i have a listing of all the members and not any groups in the member list.

Share this post


Link to post
Share on other sites

Hi gcue,

I assume you are talking about Active Directory groups?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

no, lotus notes dist list groups =)

Share this post


Link to post
Share on other sites

A recursively called function should do what you want.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

not sure what you mean? you mean a function which repeats the same for loop to save on code lines?

im trying to figure out on how to drill down exactly the amount of levels that i need to. no more no less =)

in other words get all the members (even from nested groups-an unknown amount of levels) as efficient as possible

Edited by gcue

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Global $fCheckNestedGroup = True
Global $sGroupName

While $fCheckNestedGroup
    _CheckNestedGroup($sGroupName)
WEnd


Func _CheckNestedGroup($s)
    [ ... your code here to enumerate the group ... ]
    If [... check for additional nested group ... ] = true then
        $fCheckNestedGroup = True
        $sGroupName = $sNestedGroupName
    Else
        $fCheckNestedGroup = False
    EndIf
EndFunc

Maybe this kind of logic will work?

Edited by mechaflash213

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

ah that seems like it would work.. let me try it..

water, i think this is what you were talking about too

thanks water/mechaflash!

Share this post


Link to post
Share on other sites

#10 ·  Posted

gcue,

Wikipedia: "Recursion is the process of repeating items in a self-similar way."

How it is used in computer sciencie s defined here.

For an AutoIt example please check my OutlookEX UDF, function_OL_FolderFind. This function calls itself until all folders have been processed.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

very cool solution water - getting stack overflow - hmmm

here's what i came up with:

Func GetGroup_Members($group_name)

    $dbView = $db.GetView("Groups")
    $doc = $dbView.GetDocumentByKey($group_name, True)

    If Not IsObj($doc) Then
        Return "INVALID_GROUP"
    EndIf

    $members = $doc.GetItemValue("Members")

    For $y = 0 To UBound($members) - 1
        If $members[$y] = "" Then ContinueLoop

        If StringInStr($members[$y], "@") = 0 And StringInStr($members[$y], "CN=") = 0 Then ;this is how i know the member is a group
            $members_nested = GetGroup_Members($members[$y]) ;so i pull group members again and add to the same array

            For $z = 0 To UBound($members_nested) - 1
                ReDim $members[UBound($members) + 1]

                $members[UBound($members) - 1] = $members[$z]
            Next
        Else
            ReDim $members[UBound($members) + 1]

            $members[UBound($members) - 1] = $members[$y]
        EndIf
    Next

    Return $members

EndFunc   ;==>GetGroup_Members
Edited by gcue

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Hi gcue,

the initial processing has to be done outside of the function - because you call this function over and over again. You just pass the starting point (the group) to the function.

This starting point has always to be of the same type - a group name, group object etc.

I think the following part of the code has to be outside the function to "calculate" the starting point.

$dbView = $db.GetView("Groups")
    $doc = $dbView.GetDocumentByKey($group_name, True)

    If Not IsObj($doc) Then
        Return "INVALID_GROUP"
    EndIf

    $members = $doc.GetItemValue("Members")

After the you start the enxt recursion level you have to assign the result ($members_nested) to the total result ($members). Now you assing $members to $members.

If you have questions I will provide more details tomorrow.

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#13 ·  Posted

hmm not sure i understand what you mean..

that section you're referrign to is how i get the members of a group - dont see how that wouldnt be a part of the recursive function.

thanks for your help water - much appreciated!

Share this post


Link to post
Share on other sites

#14 ·  Posted

I see. Then at least

$dbView = $db.GetView("Groups")
should be outside the function an passed as a parameter.

I will check the code and post an example for you to test.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#15 ·  Posted

OK. Here is some is some code for you to play with ;)

$dbView = $db.GetView("Groups")
$sGrouName = "Group name you want to process"
$aResult = GetGroup_Members($dbView, $sGroupName)
_ArrayDisplay($aResult)
Exit

Func GetGroup_Members($dbView, $group_name)

    $doc = $dbView.GetDocumentByKey($group_name, True)
    If Not IsObj($doc) Then Return ""
    $members = $doc.GetItemValue("Members")
    For $y = 0 To UBound($members) - 1
        If $members[$y] = "" Then ContinueLoop
        If StringInStr($members[$y], "@") = 0 And StringInStr($members[$y], "CN=") = 0 Then ;this is how i know the member is a group
            $members_nested = GetGroup_Members($dbView, $members[$y]) ;so i pull group members again and add to the same array
            If IsArray($members_nested) Then
                $iMembers = UBound($members)
                ReDim $members[UBound($members) + UBound($members_nested)]
                For $z = 0 To UBound($members_nested) - 1
                    $members[$imembers + $z] = $members_nested[$z]
                Next
            EndIf
        Else
            ReDim $members[UBound($members) + 1]
            $members[UBound($members) - 1] = $members[$y]
        EndIf
    Next
    Return $members

EndFunc   ;==>GetGroup_Members

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

#16 ·  Posted

actually still getting stack overflow..

ill continue to play with it..

thanks =)

Share this post


Link to post
Share on other sites

#17 ·  Posted

If you're getting stack overflow errors, you need to slow the process down (i.e. add some sleeps). What's happening is it's looping too quickly and its reading data into memory faster than it can take it out. You're trying to make the fat kid run for his cake.

1 person likes this

Spoiler

“Hello, ladies, look at your man, now back to me, now back at your man, now back to me. Sadly, he isn’t me, but if he stopped using ladies scented body wash and switched to Old Spice, he could smell like he’s me. Look down, back up, where are you? You’re on a boat with the man your man could smell like. What’s in your hand, back at me. I have it, it’s an oyster with two tickets to that thing you love. Look again, the tickets are now diamonds. Anything is possible when your man smells like Old Spice and not a lady. I’m on a horse.”

 

Share this post


Link to post
Share on other sites

#18 ·  Posted

hahahhahahahhaha love the analogy - made me laugh for a while

ill try it out

thanks mechaflash

Share this post


Link to post
Share on other sites

#19 ·  Posted

still had a stack overflow even with different sleeps in place

hmmm

Share this post


Link to post
Share on other sites

#20 ·  Posted

Can you post the exact message? Is it created by AutoIt or the operating system?


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Similar Content

    • gcue
      By gcue
      hello world.

      so im trying to build something that searches a SQLite database. there are multiple search fields and i'd like to support the sql wild card "%"

      the method im using is making this very very long - probably can be done much shorter/efficient


      if $field1 <> "" and $field2 = "" and $field3 = "" and $field4 = "" then _SQLite_QuerySingleRow(-1, "SELECT field2,field3,field4 WHERE field1='" & $field1_input & "'", $aRow) endif
      that in itself will take several lines considering all the combinations and even more so when I consider the wildcards which changes the conditions AND sqlquery also (LIKE "%field_input")

      there's gotta be an efficient way to do this...

      thanks in advance