Function Reference

_AD_GetAllOUs

Retrieves an array of OUs. The paths are separated by the '\' character.

#Include <AD.au3>
_AD_GetAllOUs([$sRoot = ""[, $sSeparator = "\"[, $iSelect = 0[, $iSearchScope = 2]]]])

 

Parameters

$sRoot Optional: OU (FQDN) where to start in the AD tree (default = "", equals "start at the AD root")
$sSeparator Optional: Single character to separate the OU names (default = "\")
$iSelect Optional: Which objects should be returned in the result (default = 0)
0 - Return OUs (Organizational Units) (default)
1 - Return CNs (Containers)
2 - Return OUs + CNs
$iSearchScope Optional: 0 = base, 1 = one-level, 2 = sub-tree (default)

 

Return Value

Success: One-based two dimensional array of OUs starting with the given OU. The paths are separated by "\"
    0 - ... \name of grandfather OU\name of father OU\name of son OU
    1 - Distinguished Name (FQDN) of the son OU
Failure: "", sets @error to:
    1 - No OUs found
    2 - Specified $sRoot does not exist
    3 - $iSelect is not an integer or < 0 or > 2

 

Remarks

If an OU contains spaces the sorting is wrong and might lead to problems in further processing.
Please have a look at http://www.autoitscript.com/forum/topic/106163-active-directory-udf/page__view__findpost__p__943892

 

Related

_AD_GetObjectsInOU

 

Example


#AutoIt3Wrapper_AU3Check_Parameters= -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#AutoIt3Wrapper_AU3Check_Stop_OnWarning=Y
#include <AD.au3>

; Open Connection to the Active Directory
_AD_Open()
If @error Then Exit MsgBox(16, "Active Directory Example Skript", "Function _AD_Open encountered a problem. @error = " & @error & ", @extended = " & @extended)

; *****************************************************************************
; Example 1
; Get a list of all OUs in the Active Directory
; *****************************************************************************
Global $aOUs = _AD_GetAllOUs()
If @error > 0 Then
    MsgBox(64, "Active Directory Functions - Example 1", "No OUs could be found " & @error)
Else
    _ArrayDisplay($aOUs, "Active Directory Functions - Example 1 - All OUs found in the Active Directory")
EndIf

; Close Connection to the Active Directory
_AD_Close()