<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Help needed with foreach query for LDAP user information in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636560#M221072</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254619"&gt;@D3mby&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Based on&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;solution, I followed another way. Below works with sample data. Could you please give it a try? You should adapt lookup lines and temp m_* variables according your count of management levels.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup ldap_users.csv 
| eventstats values(cn) as underlings by manager 
| rename manager as m_3 
| lookup ldap_users.csv cn as m_3 OUTPUT manager as m_2 
| lookup ldap_users.csv cn as m_2 OUTPUT manager as m_1 
| lookup ldap_users.csv cn as m_1 OUTPUT manager as m_0 
| foreach m_* 
    [ eval mng='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' 
    | eval managers=mvappend(managers,mng) ] 
| fields - m_* - mng - underlings 
| stats values(*) as * by managers 
| where managers!="-"&lt;/LI-CODE&gt;</description>
    <pubDate>Wed, 29 Mar 2023 16:48:18 GMT</pubDate>
    <dc:creator>scelikok</dc:creator>
    <dc:date>2023-03-29T16:48:18Z</dc:date>
    <item>
      <title>Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636254#M220962</link>
      <description>&lt;P&gt;Hey All,&lt;/P&gt;&lt;P&gt;Been banging my head for a few days with this one and will appreciate any feedback on the topic.&lt;BR /&gt;The scenario is the following:&lt;BR /&gt;- LDAP data is polled via ldapsearch and written to a csv lookup table - &lt;STRONG&gt;ldap_users&lt;BR /&gt;&lt;/STRONG&gt;- The use case is to return all subordinates under a specific person in the company&lt;/P&gt;&lt;P&gt;Here's an example of the end goal:&lt;/P&gt;&lt;P&gt;Consider the following 5 lines in the csv lookup&lt;/P&gt;&lt;P data-unlink="true"&gt;cn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;displayName&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mail&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; manager&lt;BR /&gt;dm123&amp;nbsp; &amp;nbsp; &amp;nbsp;Dean, Martin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dean.martin@test.eu&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CN=dm123,OU=T,OU=E,OU=S&amp;nbsp;&lt;STRONG&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; -&lt;/STRONG&gt;&lt;BR /&gt;ep123&amp;nbsp; &amp;nbsp; &amp;nbsp; Elvis, Presley&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; elvis.presley@test.eu&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CN=ep123,OU=T,OU=E,OU=S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dm123&lt;BR /&gt;mj123&amp;nbsp; &amp;nbsp; &amp;nbsp; Michael, Jordan&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; michael.jordan@test.eu&amp;nbsp; &amp;nbsp;CN=mj123,OU=T,OU=E,OU=S&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ep123&lt;BR /&gt;bc123&amp;nbsp; &amp;nbsp; &amp;nbsp; Bill, Clinton&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; bill.clinton@test.eu&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; CN=bc123,OU=T,OU=E,OU=S &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mj123&lt;BR /&gt;ba123&amp;nbsp; &amp;nbsp; &amp;nbsp; Buzz, Aldrin&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; buzz.aldrin@test.eu&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;CN=ba123,OU=T,OU=E,OU=S&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mj123&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;In this case, &lt;STRONG&gt;dm123&lt;/STRONG&gt; is the CEO of the company and is the direct manager of &lt;STRONG&gt;ep123. ep123&lt;/STRONG&gt; manages 1 person &lt;STRONG&gt;mj123&lt;/STRONG&gt;, who then manages two people -&amp;nbsp;&lt;STRONG&gt;bc123&amp;nbsp;&lt;/STRONG&gt;and ba123.&lt;BR /&gt;&lt;BR /&gt;What is needed - if I run a query for the user &lt;STRONG&gt;dm123&lt;/STRONG&gt; to receive everybody under them in the company structure, so in this case, all other 4 users.&lt;/P&gt;&lt;P data-unlink="true"&gt;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.&lt;BR /&gt;Here's my search so far:&lt;/P&gt;&lt;P data-unlink="true"&gt;&lt;BR /&gt;&lt;STRONG&gt;| inputlookup ldap_users WHERE ( ( manager="CN=dm123,OU=T,OU=E,OU=S" ) ) &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| search cn!="x*" cn!="y*" cn!="z*" &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| table cn, displayName, mail, dn&lt;BR /&gt;| rex field=dn "CN\=(?P&amp;lt;dn&amp;gt;[^\,]+)\,"&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| foreach dn &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;[| lookup ldap_users manager as dn OUTPUTNEW mail as mail_employee] &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| mvexpand mail_employee &lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;| search mail_employee!="-"&lt;/STRONG&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;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 &lt;STRONG&gt;cn, displayName, mail, dn&amp;nbsp;&lt;/STRONG&gt;for all their direct&amp;nbsp;subordinates - &lt;STRONG&gt;ep123&lt;/STRONG&gt;.&lt;BR /&gt;I then take the dn for them (&lt;STRONG&gt;ep123)&amp;nbsp;&lt;/STRONG&gt;and do a foreach, looking for any users who have a manager who's equal to the dn - this would be &lt;STRONG&gt;mj123&lt;/STRONG&gt;.&amp;nbsp; This provides me with the following output:&lt;BR /&gt;&lt;BR /&gt;cn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; displayName&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;mail&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; dn&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; mail_employee&lt;BR /&gt;&lt;STRONG&gt;ep123&lt;/STRONG&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;STRONG&gt;&amp;nbsp;Elvis, Presley&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;elvis.presley@test.eu&amp;nbsp; &amp;nbsp; CN=ep123,OU=T,OU=E,OU=S&amp;nbsp; &amp;nbsp;michael.jordan@test.eu&amp;nbsp;&lt;/STRONG&gt;&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;This is good, but now I have two roadblocks:&lt;/P&gt;&lt;P data-unlink="true"&gt;- 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 &lt;STRONG&gt;bc123&lt;/STRONG&gt; and &lt;STRONG&gt;ba123&lt;/STRONG&gt;.&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Any help will be extremely appreciated!&lt;/P&gt;&lt;P data-unlink="true"&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 07:06:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636254#M220962</guid>
      <dc:creator>D3mby</dc:creator>
      <dc:date>2023-03-28T07:06:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636255#M220963</link>
      <description>&lt;P&gt;Splunk essentially processes each event one at a time. Some commands work on the multiple events from the pipeline before producing an output event, but still each command processes the pipeline once.&lt;/P&gt;&lt;P&gt;The foreach command operates on each event one at a time for each field mentioned in the field list.&lt;/P&gt;&lt;P&gt;In order to do what you want, you would have to process the event pipeline multiple times. How many times you depend on your data. There is no way to tell ahead of time how many iterations would be required.&lt;/P&gt;&lt;P&gt;One way of solving this might be to write a custom command that essentially takes all the events and processes them as a set. Good luck with that.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 07:21:03 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636255#M220963</guid>
      <dc:creator>ITWhisperer</dc:creator>
      <dc:date>2023-03-28T07:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636260#M220966</link>
      <description>&lt;P&gt;Thanks, thought there might be a quick way around this that I'm missing&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 08:25:20 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636260#M220966</guid>
      <dc:creator>D3mby</dc:creator>
      <dc:date>2023-03-28T08:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636292#M220980</link>
      <description>&lt;P&gt;A few months ago, there was another question about org chart, but the user quickly deleted the question. &amp;nbsp;Although the data format is different, you can use the same technique.&lt;/P&gt;&lt;P&gt;First, let's construct the org chart. &amp;nbsp;Assume this Dean Martin empire has no more than six levels of management.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup ldap_users
| eval flatdata = cn . ":" . if(manager == "-", "", manager)
| eventstats values(flatdata) AS flatdata
| foreach 1 2 3 4 5 6 ``` assuming no more than 6 levels ```
    [| eval manager = mvappend(mvindex(split(mvindex(flatdata, mvfind(flatdata, "^" . mvindex(manager, 0) . ":")), ":"), 1), manager)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What this gives you is a manager field that contains all upperlings all the way up to Dean Martin.&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;cn&lt;/TD&gt;&lt;TD&gt;displayName&lt;/TD&gt;&lt;TD&gt;dn&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;flatdata&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;mail&lt;/TD&gt;&lt;TD&gt;manager&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dm123&lt;/TD&gt;&lt;TD&gt;Dean, Martin&lt;/TD&gt;&lt;TD&gt;CN=dm123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;dean.martin@test.eu&lt;/TD&gt;&lt;TD&gt;-&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ep123&lt;/TD&gt;&lt;TD&gt;Elvis, Presley&lt;/TD&gt;&lt;TD&gt;CN=ep123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;elvis.presley@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mj123&lt;/TD&gt;&lt;TD&gt;Michael, Jordan&lt;/TD&gt;&lt;TD&gt;CN=mj123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;michael.jordan@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bc123&lt;/TD&gt;&lt;TD&gt;Bill, Clinton&lt;/TD&gt;&lt;TD&gt;CN=bc123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;bill.clinton@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ba123&lt;/TD&gt;&lt;TD&gt;Buzz, Aldrin&lt;/TD&gt;&lt;TD&gt;CN=ba123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;buzz.aldrin@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;With this table, you can easily search up Elvis and all his underlings, e.g., using search command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| search cn = ep123 OR manager = ep123 ``` gimme Elvis and his underlings ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;cn&lt;/TD&gt;&lt;TD&gt;displayName&lt;/TD&gt;&lt;TD&gt;dn&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;flatdata&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;mail&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;manager&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ep123&lt;/TD&gt;&lt;TD&gt;Elvis, Presley&lt;/TD&gt;&lt;TD&gt;CN=ep123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;elvis.presley@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mj123&lt;/TD&gt;&lt;TD&gt;Michael, Jordan&lt;/TD&gt;&lt;TD&gt;CN=mj123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;michael.jordan@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;bc123&lt;/TD&gt;&lt;TD&gt;Bill, Clinton&lt;/TD&gt;&lt;TD&gt;CN=bc123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;bill.clinton@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ba123&lt;/TD&gt;&lt;TD&gt;Buzz, Aldrin&lt;/TD&gt;&lt;TD&gt;CN=ba123,OU=T,OU=E,OU=S&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123:mj123&lt;/DIV&gt;&lt;DIV class=""&gt;dm123:&lt;/DIV&gt;&lt;DIV class=""&gt;ep123:dm123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123:ep123&lt;/DIV&gt;&lt;/TD&gt;&lt;TD&gt;buzz.aldrin@test.eu&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV class=""&gt;dm123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;If your goal is to lookup Elvis specifically, you can construct any display you like from the above.&lt;/P&gt;&lt;P&gt;If your goal is to lookup underlings of all managers, you first sum them up using stats:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| stats values(cn) as underlings by manager
| where manager != "-"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;manager&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;underlings&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;dm123&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123&lt;/DIV&gt;&lt;DIV class=""&gt;ep123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;ep123&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123&lt;/DIV&gt;&lt;DIV class=""&gt;mj123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;mj123&lt;/TD&gt;&lt;TD&gt;&lt;DIV class=""&gt;ba123&lt;/DIV&gt;&lt;DIV class=""&gt;bc123&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Then apply your original lookup&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| lookup ldap_users cn as underlings&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Put all this together,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup ldap_users
| eval flatdata = if(manager == "-", null(), cn . ":" . manager)
| eventstats values(flatdata) AS flatdata
| foreach 1 2 3 4 5 6
    [| eval manager = mvappend(mvindex(split(mvindex(flatdata, mvfind(flatdata, "^" . mvindex(manager, 0) . ":")), ":"), 1), manager)]
| stats values(cn) as underlings by manager
| where manager != "-"
| lookup ldap_users cn as underlings&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following is data emulation that you can play with and compare with your real data.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| makeresults
| fields - _time
| eval _raw = "
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"
| multikv forceheader=1
| fields - _raw linecount
``` data emulation above for
| inputlookup ldap_users ```&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 10:43:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636292#M220980</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-28T10:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636320#M220990</link>
      <description>&lt;P&gt;Hey!&lt;BR /&gt;Thanks so much for this, it's really close to what I'm after &lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;BR /&gt;&lt;BR /&gt;The example works great with small datasets, but when you create the "flatdata" field, you basically output every combination of user+manager from all available events that you are fetching from the dataset - in my case, the csv.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="D3mby_0-1680010786116.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24580i08B6EDC0276D3927/image-size/medium?v=v2&amp;amp;px=400" role="button" title="D3mby_0-1680010786116.png" alt="D3mby_0-1680010786116.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;As you can see, I'm limiting the search to retrieve 10 results, meaning that each event's flatdata field will have 10 values(mv) in it, as it aggregates all user+manager combination from the other events as well.&lt;BR /&gt;&lt;BR /&gt;This is also true when we use the dummy dataset:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="D3mby_1-1680010892049.png" style="width: 400px;"&gt;&lt;img src="https://community.splunk.com/t5/image/serverpage/image-id/24581i04E726B50D21C012/image-size/medium?v=v2&amp;amp;px=400" role="button" title="D3mby_1-1680010892049.png" alt="D3mby_1-1680010892049.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;Now the csv that holds the user information is somewhere around 96K rows.&amp;nbsp;&lt;BR /&gt;The way I'm interpreting this, it will require each of these 96k rows to hold 96k entries about a user + manager combination in the flatdata field - no need to say, the search doesn't complete at all when I attempt this.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Mar 2023 13:47:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636320#M220990</guid>
      <dc:creator>D3mby</dc:creator>
      <dc:date>2023-03-28T13:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636485#M221043</link>
      <description>&lt;P&gt;Yes, I have to admit that I have never run inputlookup on 96K lines. &amp;nbsp;Saving a 96K-value field with each row is probably not the best use of RAM. &amp;nbsp;However, since all Splunk gets is a file and not a database, the data will have to be held somewhere. &amp;nbsp;So, I don't see an easy way out.&lt;/P&gt;&lt;P&gt;Some thoughts.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Run an external query to LDAP itself and produce an underling array on-demand as&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/225168"&gt;@ITWhisperer&lt;/a&gt;&amp;nbsp;suggested. &amp;nbsp;It will carry performance cost, of course.&lt;/LI&gt;&lt;LI&gt;Examine the use case more closely and make some choices. &amp;nbsp;See if it allows you to limit input. &amp;nbsp;For example, if there is some department code in LDAP and the org chart follows these codes. &amp;nbsp;Or if there is a employee level code and the level is automatically enforced with some known algorithm.&lt;/LI&gt;&lt;LI&gt;Run a query and store underlings chart in a CSV or KV store periodically.&lt;/LI&gt;&lt;LI&gt;If anything, examine limits.conf to lift some memory and timeout limits. &amp;nbsp;I do not quite know which knobs will help, however. &amp;nbsp;96K^2 = 9.2 billion. &amp;nbsp;That is a lot.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Speaking of limit inputs, you can restrict output of inputlookup to cn and manager because all other fields are irrelevant to this task. &amp;nbsp;But compared with the N^2 factor, this will not help the big problem.&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 08:55:15 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636485#M221043</guid>
      <dc:creator>yuanliu</dc:creator>
      <dc:date>2023-03-29T08:55:15Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636486#M221044</link>
      <description>&lt;P&gt;My thoughts exactly, but your suggestion has helped me plenty.&lt;BR /&gt;&lt;BR /&gt;Will experiment a bit further and post any positive results that I get.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 Mar 2023 08:57:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636486#M221044</guid>
      <dc:creator>D3mby</dc:creator>
      <dc:date>2023-03-29T08:57:21Z</dc:date>
    </item>
    <item>
      <title>Re: Help needed with foreach query for LDAP user information</title>
      <link>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636560#M221072</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/254619"&gt;@D3mby&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;Based on&amp;nbsp;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/33901"&gt;@yuanliu&lt;/a&gt;&amp;nbsp;solution, I followed another way. Below works with sample data. Could you please give it a try? You should adapt lookup lines and temp m_* variables according your count of management levels.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;| inputlookup ldap_users.csv 
| eventstats values(cn) as underlings by manager 
| rename manager as m_3 
| lookup ldap_users.csv cn as m_3 OUTPUT manager as m_2 
| lookup ldap_users.csv cn as m_2 OUTPUT manager as m_1 
| lookup ldap_users.csv cn as m_1 OUTPUT manager as m_0 
| foreach m_* 
    [ eval mng='&amp;lt;&amp;lt;FIELD&amp;gt;&amp;gt;' 
    | eval managers=mvappend(managers,mng) ] 
| fields - m_* - mng - underlings 
| stats values(*) as * by managers 
| where managers!="-"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 29 Mar 2023 16:48:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/Help-needed-with-foreach-query-for-LDAP-user-information/m-p/636560#M221072</guid>
      <dc:creator>scelikok</dc:creator>
      <dc:date>2023-03-29T16:48:18Z</dc:date>
    </item>
  </channel>
</rss>

