简体   繁体   中英

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

As far as I can tell by looking at other posts, using the subprocess library in Python is the most popular way to execute PowerShell commands from within Python. For example:

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

I have tested in my environment

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM