操作方法

操作方法:使用 ArcGIS API for Python 确定 ArcGIS Enterprise 门户和 ArcGIS Online 中的上次登录日期

Last Published: September 12, 2023

摘要

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.

原因


 

过程

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.

    文章 ID: 000022604

    接收通知并查找新问题或常见问题的解决方案

    从我们全新的 AI 聊天机器人中获得简明答案和视频解决方案。

    下载 Esri 支持应用程序

    相关信息

    发现关于本主题的更多内容

    获取来自 ArcGIS 专家的帮助

    联系技术支持部门

    下载 Esri 支持应用程序

    转至下载选项