bstjohn Posted May 18, 2016 Share Posted May 18, 2016 I'm trying to figure out a way to traverse a directory tree using LDAP. I've read a lot of posts here and mainly they involve using functions designed specifically for Active Directory. I want this to be more generic so it will work whether it's Novell eDirectory, Active Directory, etc. In my case I have both, but I primarily use eDirectory. Here's what I've got so far: $ObjLDAP = ObjGet("LDAP://192.168.1.1:389/O=MyORG") ; Not the real IP address $x=0 For $oObj In $ObjLDAP $x+=1 ConsoleWrite($x & ") cn=[" & $oObj.cn & "]" & @CRLF) $c=0 For $class in $oObj.objectClass $c+=1 ConsoleWrite(@TAB & $c & ") class=[" & $class & "]" & @CRLF) If $class="organizationalUnit" Then ; Switch to this OU and list all object there. ; BUT I DON'T KNOW HOW TO DO THIS YET ; Switch back to parent container when done. EndIf Next ConsoleWrite(@CRLF) Next Exit This works in that it lists all objects in the ORG. Here's a sample of the output. expandcollapse popup1) o=[] cn=[] 1) class=[organizationalUnit] 2) class=[ndsLoginProperties] 3) class=[Top] 4) class=[ndsContainerLoginProperties] 2) o=[] cn=[] 1) class=[organizationalUnit] 2) class=[ndsLoginProperties] 3) class=[Top] 4) class=[ndsContainerLoginProperties] 3) o=[] cn=[] 1) class=[organizationalUnit] 2) class=[ndsLoginProperties] 3) class=[Top] 4) class=[ndsContainerLoginProperties] 4) o=[] cn=[] 1) class=[organizationalUnit] 2) class=[ndsLoginProperties] 3) class=[Top] 4) class=[ndsContainerLoginProperties] 5) o=[] cn=[admingroup] 1) class=[Top] 2) class=[groupOfNames] 3) class=[posixGroup] 4) class=[uamPosixGroup] 6) o=[] cn=[apchadmn-Administrators] 1) class=[Top] 2) class=[groupOfNames] 7) o=[] cn=[Everyone] 1) class=[groupOfNames] 2) class=[Top] 8) o=[] cn=[nfradmins] 1) class=[groupOfNames] 2) class=[Top] 9) o=[] cn=[nfrreportusers] 1) class=[groupOfNames] 2) class=[Top] 10) o=[] cn=[Admin] 1) class=[inetOrgPerson] 2) class=[organizationalPerson] 3) class=[Person] 4) class=[Top] 5) class=[ndsLoginProperties] 6) class=[bhPortalConfigRW] 7) class=[bhPortalConfigSecretStore] 8) class=[bhPortalConfig] 9) class=[swareUserAttr] 10) class=[swarePointers] 11) class=[posixAccount] 12) class=[uamPosixUser] 11) o=[] cn=[dnsdhcp] 1) class=[inetOrgPerson] 2) class=[organizationalPerson] 3) class=[Person] 4) class=[ndsLoginProperties] 5) class=[Top] 6) class=[posixAccount] 7) class=[uamPosixUser] 12) o=[] cn=[nfrproxy] 1) class=[inetOrgPerson] 2) class=[organizationalPerson] 3) class=[ndsLoginProperties] 4) class=[Person] 5) class=[Top] 13) o=[] cn=[UNIX Config] 1) class=[uamPosixConfig] 2) class=[Top] 3) class=[uamPosixGidNumberInfo] 4) class=[uamPosixUidNumberInfo] 14) o=[] cn=[Apache Group] 1) class=[apchadmnConfiguration] 2) class=[apchadmnServer] 3) class=[Top] 15) o=[] cn=[apchadmn-Registry] 1) class=[apchadmnConfiguration] 2) class=[apchadmnServer] 3) class=[Top] I can determine that the first four objects are OUs. But how do I switch to those contexts? Link to comment Share on other sites More sharing options...
water Posted May 18, 2016 Share Posted May 18, 2016 That's called recursion. Put everything into a function and call it to traverse the tree. The wiki has a tutorial about recursion: https://www.autoitscript.com/wiki/Recursion My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
bstjohn Posted May 24, 2016 Author Share Posted May 24, 2016 Sorry. Perhaps I did not make myself clear. I appreciate your help, but I already understand recursion. What I don't understand is how to switch to a different context in the directory service. Link to comment Share on other sites More sharing options...
water Posted May 24, 2016 Share Posted May 24, 2016 The AD UDF sets the context in function _AD_Open. To switch you would need to close the current connection using _AD_Close and call _AD_Open again with different parameters. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
bstjohn Posted May 24, 2016 Author Share Posted May 24, 2016 And is _AD_Open specific to Active Directory? Like I said in my original post, I want to keep this directory agnostic. I primarily work with Novell eDirectory, but I want my script to be able to work with any LDAP compliant directory service. Link to comment Share on other sites More sharing options...
water Posted May 24, 2016 Share Posted May 24, 2016 Yes. AD in _AD_Open stands for Active Directory. The AD UDF is Active Directory only. But it might be a good starting point for a general purpose LDAP UDF. My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
bstjohn Posted May 24, 2016 Author Share Posted May 24, 2016 Thanks. I will look at the code. Link to comment Share on other sites More sharing options...
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