Query groups per user

775
3
Jump to solution
07-03-2019 05:18 AM
MichaelMarz
New Contributor II

Hello,

I want to list all users and their groups. Actually, the script looks like this:

user_accounts = gis.users.search()
for user in user_accounts:
print(user.firstName, ";", user.email, ";", user.groups)

The output should look like this:

user1 ; user1@email.com ; group1, group2, group3

Without "user.groups" the skript is working. When querying "user.groups", a error appers.

How do I query the groups for each user?

Thank you in advance!

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
MichaelMarz
New Contributor II

The issue was, that this approach needs a Level 2 Named User. 

Even if a level 1 named user has the rights to see all groups and members, it is not the same with the python api.

I tested the lines with a level 2 named user and it worked. The groups are returned as array.

View solution in original post

3 Replies
Egge-JanPollé1
MVP Regular Contributor

Hi Michael Marz,

You may want to have a look at a script which I have published on GeoNet recently:

https://community.esri.com/people/EPolle_TensingInternational/blog/2019/03/21/a-quick-overview-of-gr... 

The script uses the ArcGIS API for Python - with groups.search() and users.search() - to get an overview of group membership within an organization. It creates a matrix - users along the y-axis and groups along the x-axis - with a 1 or a 0 to indicate wether the user is a member of the group or not. This matrix is being written to a CSV file and can be imported to an Excel spreadsheet for further analysis.

Does this serve your needs?

BR,

Egge-Jan

MichaelMarz
New Contributor II

Hello,

thank you for this script. It worked well, but my approach needs an array per group-membership. :) So it helps, but my issue was a wrong user level.

0 Kudos
MichaelMarz
New Contributor II

The issue was, that this approach needs a Level 2 Named User. 

Even if a level 1 named user has the rights to see all groups and members, it is not the same with the python api.

I tested the lines with a level 2 named user and it worked. The groups are returned as array.

View solution in original post