"Ib Schrader" <ibschrader@xxxxxx> wrote in message
news:%23uyBxDJ%23IHA.4816@xxxxxx
>I made it work actually
>
> Disregard this post
> Usually people start at the parent level (perhaps at the domain) and use a
recursive routine to enumerate the child OU's. You are starting at the
lowest level and working up to the domain (or top level OU). A recursive
routine is still the most straightforward method (to handle any level of
nesting), but you need to test the class of the parent object to determine
when you have reached the domain. For example:
=========
Option Explicit
Dim objOU
Set objOU = GetObject("ldap://ou=subtest,ou=test,dc=domain,dc=com")
Call EnumOUs(objOU)
Sub EnumOUs(objChild)
Dim objParent
Set objParent = GetObject(objChild.Parent)
If (objParent.Class = "organizationalUnit") Then
Wscript.Echo objChild.ou & ";" & objParent.ou
Call EnumOUs(objParent)
Else
Wscript.Echo objChild.ou & ";" & objParent.distinguishedName
End If
End Sub
--
Richard Mueller
MVP Directory Services
Hilltop Lab -
http://www.rlmueller.net
--