HOW TO

Exportieren einer Liste der Portal-Benutzer in eine CSV-Datei mit der ArcGIS API for Python

Last Published: July 19, 2023

Zusammenfassung

In some instances, it is necessary to export a list of organization users from Portal for ArcGIS. This can be done using the ListUsers command line utility, or Admin Tools for ArcGIS Online.

This article provides a workaround using ArcGIS API for Python to populate an empty CSV file with a list of portal users and the required properties, such as the username, role, and email.

Vorgehensweise

  1. Import the necessary modules.
import csv  
from arcgis.gis import GIS
  1. Specify the user credentials, and connect to Portal for ArcGIS.
gis = GIS("https://<gisserver>.<domain>.com/arcgis", "username", "password", verify_cert=False)
  1. Create a new CSV file, and specify the file path.
outputFile = r"<full file path>"
  1. List all the users.
users = gis.users.search()

#For organization with more than 100 users,
users = gis.users.search('*',  max_users=<number_of_users>)
Note:
The default maximum number of the search() function is 100.
  1. Specify the fields to be displayed, and populate the data to the output file.
with open(outputFile, 'w', newline='') as ResultFile:
    wr = csv.writer(ResultFile)
    header = 'Username', 'Role', 'Email'
    wr.writerow(header)
    for user in users:
        UserRow = user.username, user.role, user.email
        wr.writerow(UserRow)

The following shows a sample of the full script:

import csv 
from arcgis.gis import GIS

gis = GIS("https://test.esri.com:7443/arcgis", "username", "password", verify_cert=False)

outputFile = r"C:\Users\Desktop\test.csv"

users = gis.users.search('*',  max_users=1000)

with open(outputFile, 'w', newline='') as ResultFile:
    wr = csv.writer(ResultFile)
    header = 'Username', 'Role', 'Email'
    wr.writerow(header)
    for user in users:
        UserRow = user.username, user.role, user.email
        wr.writerow(UserRow)

Artikel-ID:000015496

Hilfe von ArcGIS-Expert*innen erhalten

Technischen Support kontaktieren

Die Esri Support-App herunterladen

Zu den Download-Optionen

Zugehörige Informationen

Weitere Informationen zu diesem Thema erkunden