Hey All, Been banging my head for a few days with this one and will appreciate any feedback on the topic. The scenario is the following: - LDAP data is polled via ldapsearch and written to a csv lookup table - ldap_users - The use case is to return all subordinates under a specific person in the company Here's an example of the end goal: Consider the following 5 lines in the csv lookup cn displayName mail dn manager dm123 Dean, Martin dean.martin@test.eu CN=dm123,OU=T,OU=E,OU=S - ep123 Elvis, Presley elvis.presley@test.eu CN=ep123,OU=T,OU=E,OU=S dm123 mj123 Michael, Jordan michael.jordan@test.eu CN=mj123,OU=T,OU=E,OU=S ep123 bc123 Bill, Clinton bill.clinton@test.eu CN=bc123,OU=T,OU=E,OU=S mj123 ba123 Buzz, Aldrin buzz.aldrin@test.eu CN=ba123,OU=T,OU=E,OU=S mj123 In this case, dm123 is the CEO of the company and is the direct manager of ep123. ep123 manages 1 person mj123, who then manages two people - bc123 and ba123. What is needed - if I run a query for the user dm123 to receive everybody under them in the company structure, so in this case, all other 4 users. So far I'm swinging at using foreach to iterate over the ldap tree, but I can't figure out how to do multiple iterations. Here's my search so far: | inputlookup ldap_users WHERE ( ( manager="CN=dm123,OU=T,OU=E,OU=S" ) ) | search cn!="x*" cn!="y*" cn!="z*" | table cn, displayName, mail, dn | rex field=dn "CN\=(?P<dn>[^\,]+)\," | foreach dn [| lookup ldap_users manager as dn OUTPUTNEW mail as mail_employee] | mvexpand mail_employee | search mail_employee!="-" In manager= in the above, you would enter the person from who the iteration should begin. In this case, the CEO. The output returned is the cn, displayName, mail, dn for all their direct subordinates - ep123. I then take the dn for them (ep123) and do a foreach, looking for any users who have a manager who's equal to the dn - this would be mj123. This provides me with the following output: cn displayName mail dn mail_employee ep123 Elvis, Presley elvis.presley@test.eu CN=ep123,OU=T,OU=E,OU=S michael.jordan@test.eu This is good, but now I have two roadblocks: - How to use mj123 (any piece of information-mail/dn/cn, doesn't matter which we chose for the example) to iterate once more and return bc123 and ba123. Any help will be extremely appreciated!
... View more