I realize that you can query all groups a particular user is an owner of, like this: groups = gis.groups.search(query='owner:Portal_Admin') , but I want to query all groups that a particular user is a member of. Like this: groups = gis.groups.search(query='member:Portal_Admin'). Is this possible?
Solved! Go to Solution.
I've got a simple script which should list all portal users in an output csv, with a column containing a list of all their group memberships). It might be helpful.
from arcgis.gis import GIS
import pandas as pd
import datetime
url = 'https://yourportal/portal/'
username = ''
password = ''
out_csv = r'C:\portal_group_membership.csv'
gis = GIS(url, username, password)
user_list = gis.users.search(max_users=10000)
user_group = []
for user in user_list:
group_list = []
for group in user.groups:
group_list.append(group.title)
created_time = datetime.datetime.fromtimestamp(user.created/1000).strftime('%Y-%m-%d %H:%M:%S')
try:
last_login_time = datetime.datetime.fromtimestamp(user.lastLogin/1000).strftime('%Y-%m-%d %H:%M:%S')
except:
last_login_time = -1
user_group.append([user.username, user.fullName, user.email, user.level, created_time, last_login_time, (group_list)])
user_group_df = pd.DataFrame(user_group, columns =['User', 'Full_Name', 'Email', 'Level', 'Created_Date', 'Last_Login', 'Groups'])
user_group_df.to_csv(out_csv)