How to export a csv list of members in a specific group in enterprise

702
4
01-25-2024 09:39 PM
KikSiops
New Contributor III

Hi, 

How to export a csv list of members in a specific group in enterprise? I am able to generate some of its data: owner, Title, Date creation, date modified...  I am using Notebook in ArcGIS Pro.

thanks in advance for your help.

KikSiops_0-1706247507414.png

 

0 Kudos
4 Replies
KikSiops
New Contributor III

update: I am able  to generate using this tool:

PanunTools/docs/README_CreateGroupMemberListAGOL.md at main · mpanunto/PanunTools · GitHub

But I am still very keen to know how to run in from notebook.

thank you!

Dan_Brumm
Occasional Contributor II

I have a notebook I use to write out all the users that belong to a specific group to a CSV. Is that all you need? 

Daniel Brumm
GIS Nerd
0 Kudos
KikSiops
New Contributor III

@Daniel yes please. Thanks in advanced.

0 Kudos
Dan_Brumm
Occasional Contributor II
import os,csv,time

# group name to search for
group_name = 'GROUP NAME'
group = gis.groups.search(query=f'title:{group_name}')[0]

#get all the group members
accountList = group.get_members()


# create new csv file
csv_path = os.path.join(os.getcwd()+ "_Users_" + time.strftime("%b%d%Y_%H%M%S") + ".csv")

# open and write to csv
with open(csv_path, 'w',newline ='') as output:
    dataWriter = csv.writer(output)
    try:
        # Write list to CSV
        dataWriter.writerows(accountList['users'])
        
    except:
        print("count not write the list ")
        
output.close()

It's not perfect but it should work. 

You will need to get a GIS object and input the group name you want to search for

Daniel Brumm
GIS Nerd
0 Kudos