![](/img/trans.png)
[英]Trouble running PowerShell command with subprocess library in Python script runbook (Azure automation account)
[英]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.