繁体   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