Hi @chill_gis_dude
Here's an implementation, code is commented. I have an issue with accessing some users' groups.
from arcgis import GIS
import csv
## connect to agol/portal
agol = GIS("home")
## csv filepath for file creation/overwrite
csv_filepath = r"path\to\user_groups.csv"
## get a list of user objects
users = agol.users.search(max_users=1000)
## create/overwite csv
with open(csv_filepath, 'w', newline="") as csv_file:
writer = csv.writer(csv_file)
## write the header
writer.writerow(["username", "email", "groups"])
## iterate through users
for user in users:
print(user)
## write a new row with info per user
try:
groups = ",".join([group.title for group in user.groups])
new_row = [user.username, user.email, groups]
writer.writerow(new_row)
## i have instances where I cant seem to access a users groups
## you may or may not encounter this issue
except:
new_row = [user.username, "", ""]
writer.writerow(new_row)
print("\t FAILED")
## save the file
csv_file.close()
~ learn.finaldraftmapping.com