I'm an owner in a Group in Portal. I cannot find a was to select all members and then export to a CSV file.
Solved! Go to Solution.
The following python code extracts group members based on number of groups you want. (Here it's set to 10 groups). Just input the portal url, your credentials and the path to the output csv file.
from arcgis.gis import GIS
import pandas as pd
gis = GIS(portalURL, username, password)
group_members_list = []
groups = gis.groups.search('*', max_groups=10)
for group in groups:
groupMembers = group.get_members()['users']
dictionary = {'Group Name':group.title,'Group Members':groupMembers}
group_members_list.append(dictionary)
df = pd.DataFrame(group_members_list)
df.to_csv(r'path to ...group_members.csv',index=False)
Hmmm...I know Administrators of the Portal can use a command line to list members of the Portal and export it out as a *.txt file using the ListUsers utility. Not sure if it can do the same for only a Group.
Hey Joe,
This can be accomplished using the ArcGIS API for Python. Ex:
from arcgis.gis import GIS import csv portalURL = 'https://countysandbox.maps.arcgis.com' username = 'jskinner_CountySandbox' password = '******' outputFile = r'C:\temp\output.csv' groupName = 'Citizen Problem Reporter' gis = GIS(portalURL, username, password) group = gis.groups.search('title:{0} AND owner:{1}'.format(groupName, username), max_groups=15)[0] groupMembers = group.get_members()['users'] with open(outputFile, 'w') as output: dataWriter = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL, lineterminator='\n') dataWriter.writerow(['Username']) for user in groupMembers: dataWriter.writerow([user]) output.close()
Ok is this script calling out to the AGOL platform? What if we have an on-prem Enterprise Portal developed, and I have many groups that I need to export users list? Will the above still work, I am getting the following error:
IndexError Traceback (most recent call last) <ipython-input-1-222164fc7561> in <module> 10 gis = GIS(portalURL, username, password) 11 ---> 12 group = gis.groups.search('title:{0} AND owner:{1}'.format(groupName, username), max_groups=15)[0] 13 groupMembers = group.get_members()['users'] 14 IndexError: list index out of range
The following python code extracts group members based on number of groups you want. (Here it's set to 10 groups). Just input the portal url, your credentials and the path to the output csv file.
from arcgis.gis import GIS
import pandas as pd
gis = GIS(portalURL, username, password)
group_members_list = []
groups = gis.groups.search('*', max_groups=10)
for group in groups:
groupMembers = group.get_members()['users']
dictionary = {'Group Name':group.title,'Group Members':groupMembers}
group_members_list.append(dictionary)
df = pd.DataFrame(group_members_list)
df.to_csv(r'path to ...group_members.csv',index=False)
That worked thank you very much. Now I just need to format it.
Curious. If I need to get the output for each groupMember's First and Last Name and email for each member of the group?
We're you able to get the output to list names and emails? I'm needing to do the same so would be curious to know your method if you were able. Thanks!
How would I manipulate this code, so that the output CSV has a line for each user, with a column with the group names concatenated in it (rather than the other way around)?
Thanks