Different means of obtaining Azure AD login records in Python without relying on the subprocess library or powershell.exe

After researching various sources, it seems that the subprocess library in Python is commonly used to run PowerShell commands from within Python. For instance:

data = subprocess.check_output(["powershell.exe", "Connect-AzureAD -AccountId <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8a5ad88a5ade6aba7a5">[email protected]</a> \n Get-AzureADAuditSignInLogs"]).decode(sys.stdout.encoding)

Nevertheless, my end goal is to incorporate this script into an automation account in Azure. Using the executable "powershell.exe" in the script might not function correctly in an Azure automation account runbook (resulting in a "FileNotFound" error).

Is there an alternative method to retrieve sign-in log data from within Python that would be more suitable for use in an Azure automation account runbook? Perhaps the Azure library can be utilized to acquire sign-in log data instead?

Answer №1

After running tests in my own setup,

You have the option to utilize the MS Graph API query within your python code to access the Azure AD sign in logs for users.

Refer to the following example python script:

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)

For additional information, you can visit:: Querying Microsoft Graph API with Python | by Ephraim Mwai | Towards Data Science

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Set a pandas-filtered value as a variable in Python

Having an issue with using pandas to filter data from a column in my worksheet and assign values to variables. The code snippet below shows my attempt at filtering: variable = clientes.loc[(clientes['Data']=='08/02/2023')] print(variab ...

Discovering the method to locate and interact with a concealed file upload field using Selenium WebDriver in

Here is the HTML code I am working with: <a id="buttonToUpload" class="btn-pink medium" href="#"> <span class="icon-arrow-right">upload photo</span> </a> <form id="form1" enctype="multipart/form-data"> <input id="u ...

Issue with the format of incoming data in Ajax post request when working with Django framework

Hello everyone, I am currently working on a script to send a post request to my Django backend. My goal is to have the data in Json format. <input id ="my" type="submit" onclick="me()"/> <script> function me() { var data2 =JSON.stringif ...

Deleting rows and columns in Python's CSV module

I've spent time researching and reading multiple pages on Google before reaching out for help. I assure you, due diligence has been done. My goal is to open a CSV file in Python, read it, make changes, and then save the edited data into a new file. ...

Error: WebDriverException - Error message: Unable to establish connection with Chrome browser, despite working perfectly just a minute

For the past 15 minutes, my Selenium scraper was functioning perfectly fine until it suddenly started throwing an error every time I run it. Here is the relevant code snippet: searchDate = wait.until(EC.element_to_be_clickable((By.XPATH, "/input[@placehol ...

Leveraging the power of sqlite3 alongside the flexibility of k

conn = sqlite3.connect('business_database.db') c = conn.cursor() c.execute("INSERT INTO business VALUES(self.nob_text_input.text, self.post_text_input.text, self.descrip_text_input.text )") conn.commit() conn.close() I am attempting ...

Execute a click action on a web element using Python's Selenium only if

Currently working with Python Selenium, my goal is to verify the visibility of an element and then proceed to click on it if visible... # Verify whether the element is visibly displayed checkElement = driver.find_element_by_xpath("//a[@id='form1& ...

PyCurl is experiencing significant delays in completing its operations

Following the installation of a fresh system on my PC (Windows 10 x64), I am experiencing some challenges with the pycurl lib for python. I tested it on both Python 2.7 and 3.4, but the issue persists regardless of the version. The response time after se ...

Error: Optimization for a pipeline has not been completed. To resolve, ensure that fit() is called first. Issue encountered with TPOT Automated Machine Learning tool in Python

Whenever I run a sample code, I keep running into this issue: "RuntimeError: A pipeline has not yet been optimized. Please call fit() first." The Challenge with TPOT Automated Machine Learning in Python. I am attempting to replicate the example: Dataset ...

Clicking on a specific tab within a webpage in order to enable selenium to extract data

from selenium import webdriver from selenium.webdriver.chrome.options import Options from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By from t ...

Discovering the URL of an img tag within a CSV file column containing numerous links and then cross-referencing that link with another CSV file

import csv # Open the Topic or Reply file for reading csvfile = open('rad.csv', newline='') reader = csv.reader(csvfile) csvfile1 = open('new.csv', newline='') reader1 = csv.reader(csvfile1) # Extract image sources f ...

The chunk size is not initiating from the initial row in the CSV file

I am working with a large CSV file in Python 3 that I need to split and save into two separate files. Using the chunksize parameter, I specify how many rows should be included in each file. The first code is designed to read the specified number of row ...

SQLFORM that does not include a submit button

Currently working with the web2py framework, I am faced with a challenge in creating a SQLFORM without a submit button. The issue arises from having multiple forms on the page, some of which share common fields, making it impossible to use SQLFORM.factor ...

Assign a CSS class to a specific option within a SelectField in a WTForms form

Could someone explain the process of assigning a CSS class to the choices values? I am looking to customize the background of each choice with a small image. How can this be done using wtforms and CSS? class RegisterForm(Form): username = TextField( ...

How Python Flask sends a string as &#34 to an HTML page

I am working on a Flask app and I need to send simple JSON data from the app.py file to an HTML page. Here is the relevant code in my app.py: jsonArr = [{"type": "circle", "label": "New York"}, {"type": "circle", "label": "New York"}] return ...

Difficulty accessing CSV files in Pandas due to KeyError

I have successfully used pandas to create a CSV file, but I encountered an error during the process: Traceback (most recent call last): File "C:\Users\Manoj Kumar\PycharmProjects\trex\venv\lib\site-packages\pandas ...

Guide on processing a hefty JSON file by rounding decimals to the nearest integer and calculating the average of y values when there are duplicate x values

I am currently exploring ways to efficiently filter and parse through extensive JSON data sets. My main goal is to round the x values to the nearest integer. In cases where there are duplicate entries, I aim to calculate the average of the y values while ...

Mastering array/dataframe slicing (numpy/pandas)

Currently, my goal is to create 50 random samples of 30 consecutive day periods from a dataset of corn prices that are organized by date. My progress so far involves selecting 50 random days. However, I am now looking to generate an array of dataframes, e ...

Exploring the Possibilities of Automating React Material UI Input Fields with Selenium

Seeking guidance on automating data entry for media files post upload. Using Selenium to navigate the media library, but stuck on sending input to fields. The website is built with React Material UI, requiring xpath use exclusively, which is effective so ...

Problem with mobwrite - daemon refuses to initiate

I tried setting up MobWrite by following the instructions at http://code.google.com/p/google-mobwrite/wiki/Daemon, but encountered an issue when attempting to start the daemon. The error message received was as follows: (any ideas on how to resolve this? ...