How to Get all the users in Portal (more than 10,000)

813
4
07-20-2022 04:35 PM
Sunnywaygis
New Contributor III

Hi There, I am trying to build a script that searches all the users and their last login in our portal environment (10.9.1). The code snippet below works fine but it has a limit of 10000.  I found that  advanced_search allows returns all the users but I am not able to get the right syntax. Just wanted to check the proper syntax for a search that brings all the users. 

 search = gis.content.advanced_search(query='', max_items=100)

 

users = arcgis.gis.UserManager(gis)
allUsers = users.search(query = '*', max_users = 10000)

     for user in allUsers:
            if user.lastLogin != -1:
                last_accessed = time.localtime(user.lastLogin/1000)



 

 

0 Kudos
4 Replies
jcarlson
MVP Esteemed Contributor

I don't have that many users to adequately test, but usually setting the max_users parameter to -1 does the trick. Do you still hit the 10000 limit with that?

- Josh Carlson
Kendall County GIS
0 Kudos
Sunnywaygis
New Contributor III

Thanks jcarlson for your suggestion. We dont have 10,000 users at this time, I dont have a way to test this but I wanted to script to accommodate for this scenario. 

 

 

0 Kudos
HenryLindemann
Esri Contributor

Hi @Sunnywaygis,

Well usually   I would use the below code to get the users but going over 10 000 there seems to be some hard limit so you can use the below code and specify the users manually or get them through a rest query,

I would also query and use the users one at a time because you are downloading a lot of objects. but the below code will download all the users of a enterprise we also add the portal_id for AGOL otherwise you get public content and the !_esri to ignore Esri built in users.

user_manager = arcgis.gis.UserManager(con)
portal_id = 0123456789ABCDEF # for arcgis enterprise only
users_count = user_manager.advanced_search(query=f"{portal_id} AND !_esri", return_count=True)

users = []
for user_num in range(1,users_count +1):
    try:
        user = user_manager.advanced_search(query=f"{portal_id} AND !_esri",start=user_num, max_users=1)
        users.append(user)
    except Exception as e:
        print(f"User {user_num} failed")
for user in users:
    print(user)

 

Sunnywaygis
New Contributor III

Thanks HenryLindemann for the code snippet. I will give this a try and this working. We still wont know until we cross 10,000 user limit. 

Thanks again for your help. 

 

0 Kudos