How to use arcpy to get a list of Portal users

3844
4
Jump to solution
10-19-2015 05:02 AM
PaulHaakma
Regular Contributor

Hi all

Does anyone know of a way to use arcpy to obtain a list of the current users in a Portal?

I'm trying to set up a python script that reconciles versioned datasets each night, and instead of hardcoding the usernames to search for in the versions I would prefer that the script got the list of current users directly from Portal.

Any ideas?

Cheers,

-Paul

0 Kudos
1 Solution

Accepted Solutions
NeilAyres
MVP Frequent Contributor

Get portalpy from esri/github.

There is a portal.get_org_users() method to the portal object.

And a bunch of other useful portal functions

View solution in original post

4 Replies
NeilAyres
MVP Frequent Contributor

Get portalpy from esri/github.

There is a portal.get_org_users() method to the portal object.

And a bunch of other useful portal functions

View solution in original post

RebeccaStrauch__GISP
MVP Esteemed Contributor

The link to what Neil mentions  Esri/portalpy · GitHub

and description...

Portalpy

Portalpy is a Python module that allows you to administer Portal for ArcGIS and ArcGIS Online.

Features

  • Designed to be easy. Most tasks require just a few lines of code.
  • Allows user and group management.
  • Fully-documented.
  • Includes unit tests.

https://github.com/Esri/portalpy#requirementsRequirements

  • Python 2.7
  • Works with ArcGIS Online and all versions of Portal.
PaulHaakma
Regular Contributor

Thanks Neil

That's exactly what I needed - didn't know it existed but after a quick look I can see it becoming very useful.

Cheers,

-Paul

0 Kudos
AnnStark2
New Contributor II

Using the ArcGIS API for Python:

from arcgis.gis import GIS
# replace the your URL, your username and your password with the relevant
# information for your organization
# you must use an admin account to generate users

gis = GIS("https://<your URL> /portal", "<your username>","<your password>")
users = gis.users.search("*")
for i in users:
    print(i.username, " " , i.email)
    # see https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#user
    # for other things you can print out for each user
    # see https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#usermanager
    # for ways to search and sort users