Jump to content

Recommended Posts

Posted

Hi Guys/Gals,

I'm using the AD UDF to interogate our AD (the computers section, which we have under an OU of managed), what I'm trying to do (and failing horribly) is recurse through the sub OU's and place them inside a treeview container.

e.g Access |

                  |-Teachers

                  |- Students

                  |-Office

but I can't get it to go past the first sub OU, and it's creating duplicates...

my code is below

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

$ADToolbox = GUICreate("ADToolbox", 1245, 789, 192, 124)
$Root = GUICtrlCreateTreeView(8, 8, 241, 769, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_BORDER))
$Itemspane = GUICtrlCreateListView("", 256, 8, 801, 681)
$taskprog = GUICtrlCreateProgress(256, 696, 801, 25, BitOR($PBS_SMOOTH,$PBS_MARQUEE,$WS_BORDER))
GUISetState(@SW_SHOW)

_AD_Open()
Global $aOUs = _AD_GetAllOUs("OU=Computers,OU=Managed,DC=SCHOOL,DC=LOCAL", "", 0)
If @error > 0 Then
    MsgBox(48, "Active Directory Functions", "No OUs could be found")
Else
    $iCount = 2
    Do
        $sOU = "ou=" & StringReplace($aOUs[$iCount - 1][0], "\", ",ou=") & "," & $sAD_DNSDomain
        $trunk = stringsplit($sOU, ",")
            if $trunk[0] > 4 Then
            $leafcount = 0
            $branchno = 0
            do
                if $branchno = 0 then
                    if $trunk[5] <> "DC=Local" and $trunk[5] <> "DC=SCHOOL" then
                        $branch = GUICtrlCreateTreeViewItem($trunk[5], $root)
                        $branchno = 1
                        $leafcount = $leafcount + 1
                    else
                        $leafcount = $leafcount + 1
                    EndIf
                Else
                    $count = 0
                    $leafname = 0
                    do
                        if $leafname = 0 Then
                            if $trunk[6] <> "DC=Local" and $trunk[6] <> "DC=SCHOOL" then
                                $leaf = GUICtrlCreateTreeViewItem($trunk[6], $Branch)
                                $leafname = 1
                                $count = $count + 1
                            else
                                $count = $count + 1
                                $leafname = 0
                            EndIf
                        endif
                    until $count = $trunk[0]
                    $leafname=0
                    $branchno = 0
                    $count = 0
                EndIf
            until $leafcount = $trunk[0]
                $leafcount = 0
                $branchno = 0
            EndIf

        $iCount=$iCount+1
    until $iCount = $aOUs[0][0]
EndIf


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

thanks in advance

RichE

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Posted

Ok I've revised the code a little, but I've still getting duplicates...

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <ProgressConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <AD.au3>

$ADToolbox = GUICreate("ADToolbox", 1245, 789, 192, 124)
$Root = GUICtrlCreateTreeView(8, 8, 241, 769, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_BORDER))
$Itemspane = GUICtrlCreateListView("", 256, 8, 801, 681)
$taskprog = GUICtrlCreateProgress(256, 696, 801, 25, BitOR($PBS_SMOOTH,$PBS_MARQUEE,$WS_BORDER))
GUISetState(@SW_SHOW)

_AD_Open()
Global $aOUs = _AD_GetAllOUs("OU=Computers,OU=Managed,DC=SCHOOL,DC=LOCAL", "", 0)
If @error > 0 Then
    MsgBox(48, "Active Directory Functions", "No OUs could be found")
Else
    dim $iCount, $branch, $branchname, $x, $l, $leafname
    $iCount = 3
    Do
        $sOU = StringReplace($aOUs[$iCount - 1][0], "\", ",OU=") & "," & $sAD_DNSDomain
        $branch = StringSplit($sOU, ",")
        if $branch[0] > 4 and $branch[5] <> "DC=SCHOOL" and $branch[5] <> "DC=LOCAL" then
            $branchname = GUICtrlCreateTreeViewItem($branch[5], $root)
            for $x = 6 to $branch[0]
                IF $branch[$X] <> "DC=SCHOOL" and $branch[$x] <> "DC=LOCAL" Then
                    $leafname = GUICtrlCreateTreeViewItem($branch[$x], $branchname)
                EndIf
            Next
        EndIf
        $iCount=$iCount+1
    until $iCount = $aOUs[0][0]
EndIf




While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

any ideas

RichE

[font="'Arial Narrow';"]Current projects[/font]

[font="'Arial Narrow';"]are on my site [/font]Sellostring

Posted

Please check the examples thread of the AD UDF. There is an example treeview script available.

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

 

Posted

The example has a problem if there are spaces in the OU name. But there is a workaround available.

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

 

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
×
×
  • Create New...