簡體   English   中英

"在不使用子進程庫和 powershell.exe 的情況下,在 Python 中獲取 Azure AD 登錄日志的替代方法"

[英]Alternate way to get Azure AD sign in logs in Python without using subprocess library and powershell.exe

據我通過查看其他帖子得知,在 Python 中使用 subprocess 庫是在 Python 中執行 PowerShell 命令的最流行方式。 例如:

data = subprocess.check_output(["powershell.exe", "Connect-AzureAD -AccountId me@me.com \n Get-AzureADAuditSignInLogs"]).decode(sys.stdout.encoding)

我已經在我的環境中測試過

您可以在 python 腳本中使用 MS Graph API 查詢來獲取用戶的 Azure AD 登錄日志

您可以使用以下 python 代碼:

import requests
import json

url = 'https://graph.microsoft.com/v1.0/auditLogs/signIns'
token = "access_token"

headers = {
 'Authorization': 'Bearer {}'.format(token)
}

user_response_data = json.loads(requests.get(url, headers=headers).text)
print(user_response_data)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM