I am looking for a python script that I can modify to export a csv file that shows all the groups, their users and their role. Any examples out there?
Once you have the group object, I think you can use the user_list() method to get a dictionary listing users and owners for the group.
esri_owned_groups = gis.groups.search(max_groups=1) for group in esri_owned_groups: print(group) print(group.groupid) print(group.isFav) print(group.isInvitationOnly) print(group.title) print(group.owner) print(group.user_list())
Update deleted text
I can do this and get a list of Groups (id, isFav, isInvitationOnly, owner) for a specific user using the GROUPS Object.
But how do I get a list of users and their roles from this Group Object?
esri_owned_groups = gis.groups.search('title:water', max_groups=maxResults) esri_group1 = esri_owned_groups[0] esri_group1.access print(esri_group1.groupid, esri_group1.isFav, esri_group1.isInvitationOnly) print(esri_group1.owner) time.localtime(esri_group1.created/1000)
OK I can get a list of all the groups and a few parameters...
I think I have to now query the GROUP itself to now get the users and their role in the GROUP?
Not sure how to bridge this to get the users and roles in the group....
<Group title:"2011-2016 Dill" owner:useremail@test_VDOT>5dc183991e97414retygdf1886474ea2FalseFalse2011-2016 Dilluseremail@test_VDOT
esri_owned_groups = gis.groups.search(max_groups=1) counter = 0 for group in esri_owned_groups: groupInfo = esri_owned_groups[counter] print(groupInfo) print(groupInfo.groupid) print(groupInfo.isFav) print(groupInfo.isInvitationOnly) print(groupInfo.title) print(groupInfo.owner) counter +=1 print("There are " + str(counter) + " roles")
Shouldn't be too hard, though somewhat annoyingly, a group's get_members method only returns strings. Personally, I can't get user_list to return anything.
If we query the users separately, we can merge them in using pandas.
mport pandas as pd from arcgis import GIS gis = GIS('your url') # groups grps = gis.groups.search(max_groups=10000) grp_list = [] for g in grps: for u in g.get_members()['users']: grp_list.append({'group':g.title, 'user':u}) g_df = pd.DataFrame(grp_list) #users users = gis.users.search(max_users=10000) user_list = [] for u in users: user_list.append({'user':u.username, 'role':u.role}) u_df = pd.DataFrame(user_list) # output merged doc g_df.merge(u_df, on='user', how='left').to_csv('group_users.csv')
The resulting CSV will list every unique group/user combination, complete with their role.
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.