List all users groups and the actual users in them in sql
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 10:51 AM
We have a bunch of cloud AD groups in Databricks and I can see what users are in each group by using the user interface Manage Account -> Users and groups -> Groups
I would like to be able to produce this full list in SQL. I have found the below code online to give me exactly what I want but it is in Python. There doesnt seem to be a way in SQL to do this? What I was thinking is if the SQL was a little complex I would just put it inside a SQL View and then my report could just call this view.
Also I tried to create a UDF that would use the code below (because you can use Python) but it gave me a error that [FEATURE_UNAVAILABLE] Python UDTF is not supported in your environment. To use this feature, please contact Databricks Support. SQLSTATE: 56038
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2025 11:40 AM
Try this:
SQL Query Options:
- Databricks SQL supports the
SHOW GROUPScommand to list all groups within a system. This command optionally allows filtering by specific user associations or regular expressions to identify desired groups. - The statement syntax is:
SHOW GROUPS [ WITH USER user_principal | WITH GROUP group_principal ] [ [ LIKE ] regex_pattern ];This can be used to fetch specific groups associated with users. The output provides columns likename(group name) anddirectGroup(membership type: direct/indirect or NULL if no principal is specified)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 05:36 AM
Thanks for the reply. Unfortunately with the commands SHOW GROUPS and SHOW USERS there does not seem to be a way to produce a full list of users in groups though. If there was a way to get the users first from SHOW USERS and then use that to join to the SHOW GROUPS command (like its doing in the Python code) that might work but I cant seem to get that working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-20-2025 12:34 PM
Ok. Well, my last suggestion is to have a look at the SCIM Users API, and SCIM Groups API. You should be able to make the API calls right in the notebook.
Cheers, Lou.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-22-2025 04:08 PM
API doesnt seem to work for both groups and users for azure databricks