添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

@JoePrimicias ,

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)

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)
---> 12 group = gis.groups.search('title:{0} AND owner:{1}'.format(groupName, username), max_groups=15)[0]
     13 groupMembers = group.get_members()['users']
IndexError: list index out of range

@JoePrimicias ,

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)