RogFleming Posted October 31, 2010 Posted October 31, 2010 (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 October 31, 2010 by RogFleming
RogFleming Posted October 31, 2010 Author Posted October 31, 2010 [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
RogFleming Posted November 1, 2010 Author Posted November 1, 2010 Maybe not so solved, does not resolve 3 or 4 level OU Trees
water Posted November 1, 2010 Posted November 1, 2010 Maybe not so solved, does not resolve 3 or 4 level OU TreesDid you try the following script? It seems to do what you need. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.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 (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
RogFleming Posted November 2, 2010 Author Posted November 2, 2010 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now