
Microsoft 365
Microsoft Graph API: Endpoints for Architects
Production-ready PowerShell scripts for M365 tenant assessment via Graph API: discovery, identity auditing, security posture, governance, licensing.
By Paul Bentley9 min read
On this page
- Authentication setup
- Discovery: what do we have?
- Key endpoints
- Deliverable: one-page tenant summary
- Identity & access: who can access what?
- Key endpoints
- Deliverable: Conditional Access policy export
- An opinion on CA policy management
- Privileged access review
- Security posture: is it secure?
- Key endpoints
- Deliverable: top improvement actions
- Device compliance summary
- Governance: is it compliant?
- Key endpoints
- Deliverable: MFA gap report
- Licensing & usage: what's it costing us?
- Key endpoints
- Deliverable: licence waste summary
- Putting it together: the tenant assessment
- Consolidated permissions
- Where this goes next
Every Microsoft 365 engagement I've worked starts with the same five questions:
| Question | Category |
|---|---|
| What do we have? | Discovery |
| Who can access what? | Identity and access |
| Is it secure? | Security posture |
| Is it compliant? | Governance |
| What's it costing us? | Licensing and usage |
The admin portals will give you partial answers to each of these, spread across half a dozen consoles, none of which talk to each other properly. You'll click through Entra, Intune, Defender, Purview, and the M365 Admin Centre, copying data into spreadsheets, trying to build a picture that should have taken twenty minutes but takes the better part of a day.
Graph API answers all five questions from a single interface. Developers use it to build integrations; architects use it to extract insight.
This post maps the Graph endpoints that matter for each of those five questions, with working PowerShell that produces deliverables you can hand to a client, a security team, or a board. Every script is concise for readability. The companion repository has production-ready versions with proper parameterisation and error handling.
All scripts use the Microsoft Graph PowerShell SDK v2.x and need PowerShell 7 or later. On Windows PowerShell 5.1 the SDK still works, but some syntax in these examples, notably the
??operator, doesn't.
Authentication setup
Set up authentication before mapping those endpoints. You need an Entra ID app registration with certificate-based auth. The minimum viable connection:
# App-only auth (certificate) - preferred for automation
Connect-MgGraph -ClientId $appId -TenantId $tenantId -CertificateThumbprint $thumbprint
# Or interactive auth for ad-hoc work (delegated)
Connect-MgGraph -Scopes "User.Read.All","Group.Read.All","Device.Read.All",
"DeviceManagementManagedDevices.Read.All","DeviceManagementApps.Read.All",
"Policy.Read.All","RoleManagement.Read.Directory","Application.Read.All",
"Directory.Read.All","SecurityEvents.Read.All","SecurityAlert.Read.All",
"AccessReview.Read.All","Reports.Read.All","AuditLog.Read.All",
"LicenseAssignment.Read.All"The scopes above cover everything in this post. Grant most of these as application permissions for app-only auth; they're all read-only, so nothing you grant here changes the tenant. One exception: LicenseAssignment.Read.All has no application form, so the licence detail call in the licensing section needs a delegated, signed-in session rather than the certificate or secret behind every other call in this post.