WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

ADSI
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Recursive Searching with dsGetChildPath vs dsFindPath

Keywords: 	  Recursive Searching dsGetChildPath vs dsFindPath

Question:

I can make basically the same query using dsFindPath or dsGetChildPath although dsGetChildPath does not "recurse." Assuming an OU with no sub-OUs,containers, or anything other than user accounts, do you have any idea why dsGetChildPath returns all entries, but dsFindPath always returns exactly 1000? Is there some option that I am missing to expand the result set to include more than this?

Answer:

dsFindPath and dsGetChildPath use different algorithms to obtain the desired result. This is necessary because dsFindPath is a much more generalized function. Also, you are correct, In versions 10008 and older, dsFindPath does have a limit of 1000 records in a result. This limit is removed in the current version of the extender (version 10009 or newer).

Question (cont'd):

OK, thank you. I wanted to use the dsFindPath function simply because it DOES do a "recursive" search into the AD starting at the LDAP path specified. I can make my own recursive functions to get all the paths using the child function instead, but it would have been nice to just use dsFindPath! Thanks for adding the suggestion to the list.

Answer:

Yes, in your case you can get the result you desire by recursion but in some cases this may not be necessary, if you simply refine the search.

That being said, here is an example of performing a recursive search with dsGetChildPath:

; Initialize some variables.
sAllClasses = "" ; Our results - must be initialize.
nDepth = 0 ; Always set to 0 at the start.
sPath = "LDAP://myserver" ; Our starting point in the object tree.

; This does all the work. 
gosub GetClasses

; Display the results.
message("List of classes", sAllClasses )

nCount = ItemCount(sAllClasses, @Tab)

message( "Number of classes", nCount)

exit


;********************************************************************
;* Name: GetClasses
;*
;* Purpose: Traverses an Active Directory object hierarchy. 
;* 
;********************************************************************/
:GetClasses

if strlen(sPath) == 0 then return ; This should be an error.

; Add this objects class name.
gosub AddObjectsClass

; Get child paths.
sChildPaths%nDepth% = dsGetChldPath(sPath, "")
nChildCount%nDepth% = ItemCount(sChildPaths%nDepth%, @Tab)

; Check each child.
while nChildCount%nDepth% > 0

; Get the next sibling.
sPath = ItemExtract(1,sChildPaths%nDepth%, @Tab)
sChildPaths%nDepth% = ItemRemove(1, sChildPaths%nDepth%, @Tab)

; Check the children of this sibling.
nDepth = nDepth + 1 
gosub GetClasses ; Recurse to the next level.
nDepth = nDepth - 1 

nChildCount%nDepth% = nChildCount%nDepth% - 1
endwhile

return ; GetClasses


;********************************************************************
;* Name: AddObjectsClass
;*
;* Purpose: Adds an AD object's classes to a list of class names.
;* 
;********************************************************************/
:AddObjectsClass

; Get the class names
sClassList = dsGetProperty( sPath, "objectClass")

; Objects can have more than one class.
nNameCount = Itemcount(sClassList, @TAB)
for i=1 to nNameCount

sClass = ItemExtract(i, sClassList, @Tab)

; Check if class name is already in list.
if ItemLocate (sClass, sAllClasses, @TAB) == 0

; Add to the class list. 
sAllClasses = ItemInsert(sClass, -1, sAllClasses, @TAB)
endif
next

return ; AddObjectsClass

Article ID:   W15047
File Created: 2002:10:08:10:34:24
Last Updated: 2002:10:08:10:34:24