Sign in to follow this  
Followers 0
RogFleming

Dynamic Active Directory Tree

5 posts in this topic

#1 ·  Posted (edited)

This work great for getting a Treeview of OU's that have sub OUs, but I cannot get any OU that do not

have Sub OU without getting duplicates. If there a check I can create to see if a OU has a Parent OU? or a member of another OU?

I thinking maybe that once a OU is used to delete it out of the Main Array.

Something like;

$foundou = _ArraySearch($aOUs,$chldOU[1][1])

_ArrayDelete($aOUs,$foundou)

_AD_Open()
$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
_ArraySort($aOUs)
;_ArrayDisplay($aOUs)
$ParentOU=_GUICtrlTreeView_AddChild($tviewPI, $MainOU,"OU=THR Workstations,DC=txhealth,DC=org")
For $ou = 2 to UBound($aOUs,1) -1
        $chldOU = _AD_GetAllOUs($aOUs[$ou][1])
            If $chldOU[0][0] >= 2 Then
                $ChildOU = _GUICtrlTreeView_AddChild($tviewPI, $ParentOU,$chldOU[1][1])
                For $cOU = 2 to UBound($chldOU,1) -1
                    _GUICtrlTreeView_AddChild($tviewPI,$ChildOU,$chldOU[$cOU][1])
            Next

            EndIf

Next
Edited by RogFleming

Share this post


Link to post
Share on other sites



[solved]

_AD_Open()
$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
_ArraySort($aOUs)
;_ArrayDisplay($aOUs)
$ParentOU=_GUICtrlTreeView_AddChild($tviewPI, $MainOU,"OU=THR Workstations,DC=txhealth,DC=org")
For $ou = 2 to UBound($aOUs,1) -1
        $chldOU = _AD_GetAllOUs($aOUs[$ou][1])
            If $chldOU[0][0] >= 2 Then
                $ChildOU = _GUICtrlTreeView_AddChild($tviewPI, $ParentOU,$chldOU[1][1])
                For $cOU = 2 to UBound($chldOU,1) -1
                                        $ou = $ou +1
                    _GUICtrlTreeView_AddChild($tviewPI,$ChildOU,$chldOU[$cOU][1])
            Next

            EndIf

Next

Share this post


Link to post
Share on other sites

Maybe not so solved, does not resolve 3 or 4 level OU Trees

Share this post


Link to post
Share on other sites

Maybe not so solved, does not resolve 3 or 4 level OU Trees

Did you try the following script? It seems to do what you need.

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

Did you try the following script? It seems to do what you need.

It may not be sexy like those others but this works for 3 layers

_AD_Open()
$aOUs = _AD_GetAllOUs("DC=domain,DC=org"); Sub here your domain name
_ArraySort($aOUs,0,0,0,0)
For $ou = 1 to UBound($aOUs) - 1  ;Level1 For
    $MultiOU = _ArrayFindAll($aOUs,$aOUs[$ou][1],0,0,0,1,1)

    If _ArrayMaxIndex($MultiOU) >=2 Then
        $ParentOU = _GUICtrlTreeView_AddChild($tviewPI, $MainOU,$aOUs[$MultiOU[0]][1])
            For $children = 1 to _ArrayMaxIndex($MultiOU)
                $MultiOU2 = _ArrayFindAll($aOUs,$aOUs[$MultiOU[$children]][1],0,0,0,1,1)
                If _ArrayMaxIndex($MultiOU2) >=2 Then
                    $ParentChild = _GUICtrlTreeView_AddChild($tviewPI, $ParentOU,$aOUs[$MultiOU2[0]][1])
                    $ou=$ou+1
                        For $children2 =1  to _ArrayMaxIndex($MultiOU2)
                        $Child = _GUICtrlTreeView_AddChild($tviewPI, $ParentChild,$aOUs[$MultiOU2[$children2]][1])
                        $children=$children+1
                        $ou=$ou+1
                        Next
                Else
                    _GUICtrlTreeView_AddChild($tviewPI, $ParentOU,$aOUs[$MultiOU2[0]][1])
                    $ou=$ou+1
                    $Child2ArraySize=0
                EndIf
            Next

    Else
        _GUICtrlTreeView_AddChild($tviewPI, $MainOU,$aOUs[$ou][1])
    EndIf
Next

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