HOW TO

Ermitteln der letzten Anmeldung im ArcGIS Enterprise-Portal und in ArcGIS Online mit ArcGIS API for Python

Last Published: September 12, 2023

Zusammenfassung

The last login dates are helpful in determining the list of active users in ArcGIS Enterprise portal and ArcGIS Online. Administrators have the required privileges to view audit logs and remove non-active users to free up licenses for new users. The last login dates can be determined using ArcGIS API for Python.

Ursache


 

Vorgehensweise

Complete the steps below to determine the last login date in ArcGIS Enterprise portal and ArcGIS Online using ArcGIS API for Python.

  1. Import the necessary module, including the time module.
import arcgis
import time
from arcgis.gis import GIS
    1. Make an administrator connection to ArcGIS Enterprise portal or ArcGIS Online.

    ArcGIS Enterprise portal

    gis = GIS("https://domain.esri.com/portal", username="user1", password="pass1", verify_cert=False)
    print("connected")
    

    ArcGIS Online

    gis = GIS("https://arcgis.com", username="username", password="password")
    print("connected")
    
    1. Search for the list of users in ArcGIS Enterprise portal or ArcGIS Online. Set the maximum number of users if needed.
    a_users = gis.users.search(query='', max_users=200)
    a_users
    1. Loop through the list of available users, and print the login record for ArcGIS Enterprise portal or ArcGIS Online.
    for a_user in a_users:
        if a_user. lastLogin != -1:
            last_accessed = time.localtime(a_user. lastLogin/1000)
            print(str(a_user. fullName) + " was last active on: {}/{}/{}\n".format(last_accessed[0], last_accessed[1], last_accessed[2]))
    
        else:
          print(str(a_user. fullName) + " has never logged in.\n")

    The following shows the full script:

    import arcgis
    import time
    from arcgis.gis import GIS
    
    #For Portal for ArcGIS
    gis = GIS("https://domain.esri.com/portal", username="user1", password="pass1", verify_cert=False)
    
    
    #For ArcGIS Online
    gis = GIS("https://arcgis.com", username="username", password="password")
    
    print("connected")
    
    a_users = gis.users.search(query='', max_users=200)
    a_users
    
    for a_user in a_users:
        if a_user. lastLogin != -1:
            last_accessed = time.localtime(a_user. lastLogin/1000)
            print(str(a_user. fullName) + " was last active on: {}/{}/{}\n".format(last_accessed[0], last_accessed[1], last_accessed[2]))
    
        else:
          print(str(a_user. fullName) + " has never logged in.\n")

    The image below shows the result of the above script.

    Result of the Python script.

    Artikel-ID: 000022604

    Benachrichtigungen erhalten und Lösungen für neue oder häufige Probleme finden

    Unser neuer KI-Chatbot stellt zusammengefasste Antworten und Videolösungen für Sie bereit.

    Esri Support App herunterladen

    Zugehörige Informationen

    Weitere Informationen zu diesem Thema erkunden

    Unterstützung durch ArcGIS-Experten anfordern

    An den technischen Support wenden

    Esri Support App herunterladen

    Zu Download-Optionen wechseln