I am attempting to add all the users in my org to a group.
I have been able to select the group (in this case it is called 'Nearmap').
My difficulty is in trying to select all the users. What is the command for that?
Also what is the command to then add all those users to the group 'Nearmap'?
Do you have the API reference ???
And I assume you have seen the sample notebooks
I've been through both the API reference and sample notebooks but remain stuck on the part to add the users to the group. Thanks for the reply.
Hey Ben,have you ever tried admin tools? You can do many group management tasks like what you are asking. The free tools in the ArcGIS Marketplace should accomplish what you need done.
I know the admin tools were a bit out of date. I was trying with the arcgis.gis module first. I may have to revert to the admin tools now.
hmm, not sure about out of date, fYI, the last update was Feb 2017 and of note, another update is coming very shortly. Good luck with things
I was hoping to create a python script to add all the users to a group nightly. I do have the Admin Tools Pro but it won't let me automate the steps.
On a side note I did discover how to get all the users in an organization: In this case I have a maximum number of accounts of 2000. Again thanks for any help offered.
users = gis.users.search(query="*",max_users=1200)
from arcgis import *
#declare gis
gis = GIS('portal url', 'admin user', 'admin pass')
#return list of users in portal
user = gis.users.search('', '', max_users=2000)
#specify group for method
group = gis.groups.search('title: your group title', '')
#add user list to group with specified index value since gis.groups.search returns a list
group[0].add_users(user)
#confirm users were added by calling get_members method on group with index value
group[0].get_members()
sethlewistempe very helpful.....instead of all users, how would you set "users" to be a dictionary of a subset of all users? Let's say I have a CSV of 100 users that I want added to this group....
Assuming that the users have already been added to your portal/organization, the following should get you started.
#import modules
from arcgis import *
import csv
#declare gis
gis = GIS('portal url', 'admin', 'pass')
#specify group for method
group = gis.groups.search('title: group title', '')
#print list of members
group[0].get_members()
#declare empty list of users to be added
userAdd = []
with open(r"path to csv") as f_input:
csv_input = csv.DictReader(f_input)
for row in csv_input:
users = row["provide column containing usernames"]
userAdd.append(users)
#print list result
print(userAdd)
#pass the appended list to the method
group[0].add_users(userAdd)
#confirm users were added by again calling the get_members method on the group
group[0].get_members()