Jump to content

getting members from nested upon nested groups


Recommended Posts

right.. hmm im still open to count how many times a group gets processed.. if it happens 3 times then skip it

dirty i know but at least it will stay fast.

Link to comment
Share on other sites

One time must be enough. I will post a simple example in a few minutes.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

This should do what we need. A global string contains all processed groups separated by the pipe character ("|"). Before a group is processed the string is checked. If found, don't process this group again. If not, add the group to the string and process the group.

Global $sGroupsProcessed = "|"
$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)
    
    If StringInStr($sGroupsProcessed, "|" & $group_name & "|") > 0 Then Return "" ; Group has already been processed
    $doc = $dbView.GetDocumentByKey($group_name, True)
    If Not IsObj($doc) Then Return ""
    $sGroupsProcessed = $sGroupsProcessed & $group_name & "|" ; Add processed group to string of processed groups
    $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
Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

looking gooood - no crashes! only thing now is that i think its keeping the record count when theres an incrementation of the members array as part of its members

ie:

group a had 14 members and one of them was a nested group

nested group members = 5

in the array result ill see the 14 members + the 5 + the number "14" from the first array haha

Link to comment
Share on other sites

As we never set element 0 of the resulting array to the number of elements I think

$members = $doc.GetItemValue("Members")
returns an array with the number of elements in element 0.

Change

For $y = 0 To UBound($members) - 1
to
For $y = 1 To UBound($members) - 1
and the numbers should be gone.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

So the resulting array looks like?

14

... 14 group names

5

... 5 group names

3

... 3 group names

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

When I check my code above we never set the number of elements in the array.

Did you modify the code?

Can you post the code you run?

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Func GetGroup_Members($dbView, $group_name)
 If StringInStr($sGroupsProcessed, "|" & $group_name & "|") > 0 Then Return ""
    $doc = $dbView.GetDocumentByKey($group_name, True)
    If Not IsObj($doc) Then Return "INVALID_GROUP" ;need this for later
    $sGroupsProcessed = $sGroupsProcessed & $group_name & "|"
    $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
 $unique_members = _ArrayUnique($members)
 _ArrayDisplay($unique_members)
    Return $unique_members
EndFunc   ;==>GetGroup_Members

Link to comment
Share on other sites

Don't do _ArrayUnique in the function. Do it once in the main script. Change

$unique_members = _ArrayUnique($members)
_ArrayDisplay($unique_members)
Return $unique_members
to
Return $members

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

i do it there because the main function has multiple column array and kind of difficult to do arrayunique with multiple dimensions

and sometimes theres duped members between parent and nested groups

Edited by gcue
Link to comment
Share on other sites

Then you could use _ArrayDelete to remove the first row of the array.

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

Fine. Problem solved - thread closed ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

not sure what is going on here.. it seems that the array unique is applying to the contacts array in GetContacts_XML($xml_file) function because some of the members are missing in some of the groups that are being queried. if i remove all the groups that are being queried and just leave the one that was missing members before - it works well even if it has multiple nested groups within it.

however i need the arrayunique to accurately display each group's member listing

Func GetContacts_XML($xml_file)

_XMLFileOpen($xml_file)

If FileExists($xml_file) Then
  FileDelete($xml_file)
EndIf

Local $contacts[1]

$dbView = $db.GetView("Groups")
$groups_count = _XMLGetNodeCount("/imClientConfig/contactList/group")

For $x = 1 To $groups_count
  $group_name = _XMLGetAttrib("/imClientConfig/contactList/group[" & $x & "]", "name")
   $group_members = GetGroup_Members($dbView, $group_name)

   If $group_members = "INVALID_GROUP" Then
    ReDim $invalid_groups[UBound($invalid_groups) + 1]
    $invalid_groups[UBound($invalid_groups) - 1] = $group_name
   EndIf

   For $y = 0 To UBound($group_members) - 1
    ReDim $contacts[UBound($contacts) + 1][3]
    $contacts[UBound($contacts) - 1][0] = $group_name
    $contacts[UBound($contacts) - 1][1] = $group_members[$y]
    $contacts[UBound($contacts) - 1][2] = "PUBLIC_GROUP"
   Next

Next

_ArraySort($contacts, 0, 0, 0, 0)

Return $contacts

EndFunc   ;==>GetContacts_XML

Func GetGroup_Members($dbView, $group_name)

If StringInStr($sGroupsProcessed, "|" & $group_name & "|") > 0 Then Return "" ; Group has already been processed

$doc = $dbView.GetDocumentByKey($group_name, True)
 

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

$sGroupsProcessed = $sGroupsProcessed & $group_name & "|" ; Add processed group to string of processed groups

$members = $doc.GetItemValue("Members")
;~  _ArrayDisplay($members, "before")

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

  If 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

$unique_members = _ArrayUnique($members)

If StringIsDigit($unique_members[0]) = 1 Then
  _ArrayDelete($unique_members, 0)
EndIf

for $x = UBound($unique_members)-1 to 0 step -1
  If StringInStr($unique_members[$x], "CN=") = 0 Then
   ConsoleWrite($unique_members[$x] & @CRLF)
   _ArrayDelete($unique_members, $x)
  EndIf
Next

_ArraySort($unique_members)

Return $unique_members

EndFunc   ;==>GetGroup_Members
Edited by gcue
Link to comment
Share on other sites

Wouldn't you want to reset the variable to

$sGroupsProcessed = "|"

Since your search for already-processed-groups requires a leading "|" in front of each group name?

Using the Assign()/IsDeclared() method might also accomplish what you're doing now by building and searching a string of processed group names.

typo

Edited by Spiff59
Link to comment
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
 Share

×
×
  • Create New...