This project contains:
- A PowerShell script (
setup-appregistration.ps1
) to automate Azure App Registration using Azure CLI. - A Jupyter Notebook (
graph_api_example.ipynb
) to authenticate and fetch Microsoft 365 Graph API data.
- Azure CLI installed (Installation Guide)
- Python 3.x installed (Download Python)
- Required Python packages:
pip install requests matplotlib
- Access to an Azure Subscription with permissions to create app registrations.
- Global Admin or Application Administrator role to grant Graph API permissions.
-
Open PowerShell and log in to Azure:
./setup-appregistration.ps1
This will:
- Register a new Azure AD App.
- Create a Client Secret (recycling it if one exists).
- Assign Graph API permissions (
User.Read.All
,Directory.Read.All
). - Grant Admin Consent.
- Create a Service Principal.
-
Copy the output values:
- App ID
- Client Secret
- Tenant ID
-
A file called
config.json
will be created with these credentials for use in the Jupyter Notebook.
- Ensure
config.json
exists in the working directory. - Open the notebook and edit these variables:
OR load them directly from
TENANT_ID = "" CLIENT_ID = "" CLIENT_SECRET = ""
config.json
. - Run the notebook to:
- Authenticate using Microsoft 365 Graph API.
- Fetch the number of users in the tenant.
- Generate a pie chart showing user statistics.
- The PowerShell script ensures credentials are not duplicated.
- Ensure admin consent is granted for API permissions before running the Python script.
- The Jupyter Notebook assumes at least 1 user is present in the tenant.
For troubleshooting, refer to:
- Azure CLI Docs: Microsoft Docs
- Graph API Docs: Microsoft Graph API
m365-python/
├── graph_api_example.ipynb # Jupyter Notebook with the Python example
├── setup-appregistration.ps1 # PowerShell script for app registration setup
├── requirements.txt # List of Python dependencies
└── README.md # Project documentation