All Apps and Add-ons

Splunk Support for Active Directory: Using LDAP search, how do I match groups, user names, and titles in a single table?

scottrunyon
Contributor

Using the Splunk Supporting Add-on for Active Directory, I have been tasked to find out which users are assigned to specific groups. I can get a table showing the "Common Name" of the users in each group -

|ldapsearch domain=default search="(objectClass=group)"|table cn,distinguishedName
|ldapgroup|rex field=member_dn "CN=(?P\w*\s\w*)"| table cn,UserName | rename cn AS "Group"

Results of the search looks like this

Group                           UserName
IT Support                      Fred Flintstone
[blank]                         Barney Rubble
                                       .
                                       .
Security                        Thomas Magnum
[blank]                         Frank Cannon

I then run the following search to get the title of the user -

|ldapsearch domain=default search="(&(objectClass=user)(!(objectclass=computer)))" | dedup cn title | table cn title | rename cn AS UserName, title AS Title

Search results look like this -

UserName                Title
Fred Flintstone         Computer Analyst
Barney Rubble           Senior Computer Analyst
Thomas Magnum           Security Guard
Frank Cannon            Security Manager

I what to have a table that combines the searches to look like this -

Group          UserName         Title
IT Support     Fred Flintstone   Computer Analyst
[blank]        Barney Rubble       Senior Computer Analyst
               .
               .
Security       Thomas Magnum       Security Guard
[blank]        Frank Cannon     Security Manager

I have tried join, append, appendcols and cannot get the items to line up correctly. What am I missing?

0 Karma
1 Solution

scottrunyon
Contributor

I ended up having to break the search into 2 parts, the first one creating a lookup CSV file that matched the UserName to Title

|ldapsearch domain=default search="(&(objectClass=user)(!(objectclass=computer)))"
| dedup cn title
| table cn title
| rename cn AS UserName, title AS Title
| outputlookup ldaptitletouser.csv

I then used this file to do a lookup to match up the UserName in the Group search -

|ldapsearch domain=default search="(objectClass=group)"
|table cn, member
| rex field=member "CN=(?P\w*\s\w*)"
| rename cn AS "Group"
| table Group, UserName

| lookup ldaptitletouser.csv UserName OUTPUT Title
| table Group UserName Title

Hopefully someone else can use this.

View solution in original post

0 Karma

scottrunyon
Contributor

I ended up having to break the search into 2 parts, the first one creating a lookup CSV file that matched the UserName to Title

|ldapsearch domain=default search="(&(objectClass=user)(!(objectclass=computer)))"
| dedup cn title
| table cn title
| rename cn AS UserName, title AS Title
| outputlookup ldaptitletouser.csv

I then used this file to do a lookup to match up the UserName in the Group search -

|ldapsearch domain=default search="(objectClass=group)"
|table cn, member
| rex field=member "CN=(?P\w*\s\w*)"
| rename cn AS "Group"
| table Group, UserName

| lookup ldaptitletouser.csv UserName OUTPUT Title
| table Group UserName Title

Hopefully someone else can use this.

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

SOK it to Me: Top 3 Benefits of Using Splunk Operator on Kubernetes that’ll Make ...

    Thursday, July 9, 2026  |  11:00AM–12:00PM PDT Duration: 1 hour (includes Q&A) Managing can feel like a ...

Upgrade Prep for 10.4, Network Observability Deep Dives, and More from Splunk Lantern

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

Splunk Developer Day announcements: AI agents, MCP tools, Forecasting, and Custom ...

Splunk Developer Day was packed with product and platform updates for developers building in the AI ...