Identify stale accounts with real activity data from Exchange, SharePoint, OneDrive, and Teams, then phase deprovisioning with manager notification.
Complexity: Intermediate. Impact: cost-savings + security + governance + compliance + license-optimization.
Why use this workflow
Inactive user accounts are one of the highest-leverage cleanup targets in a Microsoft 365 tenant. Every stale account typically carries a paid license, a live mailbox, OneDrive storage, and potentially SharePoint site ownership. Beyond cost, they are a security liability: dormant accounts are prime targets for password spray and phishing-based takeover.
A 90-day inactivity audit is a common governance control. This workflow walks through how to build that audit: not just by looking at Entra sign-in logs (which miss service-specific activity), but by cross-referencing the getOffice365ActiveUserDetail usage report, which includes Exchange, SharePoint, OneDrive, and Teams last-activity dates.
The output is not just a list. It is a phased deprovisioning plan with manager notifications, license removal recommendations, and safeguards against accidentally disabling executive or service accounts.
Expected outcomes
After completing this workflow you have:
- A CSV report of all users inactive for 90 or more days, with per-service last-activity dates (Exchange, SharePoint, OneDrive, Teams)
- License assignment details for each inactive user (critical for cost recovery)
- Manager name and email for each inactive user (for the notification workflow)
- A recommended action per user (review for license removal or account disable)
- A phased deprovisioning plan (notify, review, disable, remove licenses)
- A flag for high-risk accounts (executives, service accounts, shared mailboxes) that need HR or manual review
Risks and considerations
Watch out for these pitfalls
- Anonymized reports: By default, Microsoft 365 usage reports show concealed names like
5C0DBA…. You must temporarily setdisplayConcealedNamestofalsewithPATCH /admin/reportSettingsto get real UPNs. Always re-enable anonymization after the audit to stay aligned with your privacy posture. - Do not rely on
signInActivityalone: It tracks only Entra interactive and non-interactive sign-ins. A user may be inactive in Entra logs but still have Exchange mail flow or OneDrive sync activity. Use the usage report for a true picture. - Service accounts and shared mailboxes appear as inactive because they are designed to never sign in interactively. Tag and exclude them before any disable action.
- Executive accounts (C-suite, board members) often show low activity but should never be auto-deprovisioned. Escalate these to HR.
- Do not delete accounts directly. The safe sequence is: notify the manager, remove licenses, disable sign-in, convert the mailbox to shared, wait for your retention period, then delete. Skipping the shared-mailbox step can lose mail data permanently.
- Licensed but never signed in: These are often onboarding mistakes (license assigned before the user started) or offboarding failures. Investigate before you revoke.
- B2B guest users have different activity patterns and may not appear correctly in the usage report. Handle them in a separate audit.
Required permissions
| Permission | Why it's needed |
|---|---|
| Reports.Read.All | Required to call getOffice365ActiveUserDetail and related usage reports that provide per-service activity data |
| ReportSettings.ReadWrite.All | Required to temporarily disable report anonymization (displayConcealedNames) so actual UPNs and display names appear in reports |
| User.Read.All | Required to fetch per-user license assignments, accountEnabled status, department, and job title |
| Directory.Read.All | Required to read each user's manager relationship for the notification workflow |
| Organization.Read.All | Optional: needed if you want to map license SKU GUIDs to friendly product names for the report |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
Audit our M365 tenant for users inactive {days} days. Pull activity across Exchange, SharePoint, OneDrive, and Teams - not just Entra sign-ins. For each inactive user, report license count, manager, and department. Flag executives and service-account candidates separately. Output a phased deprovisioning plan with manager notifications and a CSV I can action on.
Manual steps (admin center)
The Microsoft 365 admin center provides a built-in inactive user view, though it is less detailed than the API-driven approach.
Step 1: Disable report anonymization (one-time)
- Sign in to the Microsoft 365 admin center as a Global Administrator or Reports Reader.
- Go to Settings > Org settings > Services > Reports.
- Clear Display concealed user, group, and site names in all reports.
- Select Save. Reports can take time to refresh with real names.
Step 2: Pull the active users report
- Go to Reports > Usage.
- Open the Active users: Microsoft 365 Services card.
- Set the date range to Last 90 days.
- Select Export to download the CSV.
Step 3: Identify inactive users
- Open the CSV in Excel.
- Filter
Is Deleted= FALSE. - Filter
Last Activity Date= blank or older than 90 days ago. - Cross-reference with Users > Active users to confirm the account is enabled and still licensed.
Step 4: Check SharePoint ownership
- Go to SharePoint admin center > Sites > Active sites.
- For each inactive user, filter the Primary admin column by their UPN.
- Document any sites where they are the sole owner. These need reassignment before you disable the account.
Step 5: Check mailbox size and activity
- Go to Exchange admin center > Recipients > Mailboxes.
- Search for each inactive user.
- Review mailbox size and last logon date. Larger mailboxes warrant shared-mailbox conversion before you disable the account.
Step 6: Notify the manager
- Go to Users > Active users.
- Select the user, open the Account tab, and note the Manager field.
- Send the manager an email that asks whether the account should be retained, converted, or disabled.
Step 7: Execute deprovisioning after confirmation
- Remove licenses: select the user, then Licenses and apps, clear all licenses, and select Save.
- Block sign-in: select the user, then Account > Block sign-in.
- Convert the mailbox: Exchange admin center > mailbox > Convert to shared mailbox.
- After your retention period, delete the user from Users > Deleted users.
Step 8: Re-enable report anonymization
Return to Settings > Org settings > Services > Reports and select the anonymization option again.
Microsoft Graph API
The end-to-end flow uses four endpoints: read report settings, toggle anonymization, pull the usage report, and enrich each inactive user with license and manager data.
1. Check current report anonymization setting
GET https://graph.microsoft.com/v1.0/admin/reportSettings
// Response
{
"displayConcealedNames": true
}2. Disable anonymization (temporarily)
PATCH https://graph.microsoft.com/v1.0/admin/reportSettings
Content-Type: application/json
{
"displayConcealedNames": false
}
// Returns 204 No Content3. Pull the 90-day Office 365 activity report
GET https://graph.microsoft.com/v1.0/reports/getOffice365ActiveUserDetail(period='D90')
// Returns CSV. Key columns:
// User Principal Name, Display Name, Is Deleted,
// Last Activity Date, Exchange Last Activity Date,
// SharePoint Last Activity Date, OneDrive Last Activity Date,
// Teams Last Activity Date, Has Exchange License, ...4. For each inactive user, fetch license and manager
GET /v1.0/users/{upn}?$select=id,assignedLicenses,accountEnabled,department,jobTitle
GET /v1.0/users/{id}/manager?$select=displayName,userPrincipalName
// Returns 404 if no manager is assigned - handle gracefully5. (Optional) Check SharePoint site ownership
GET /v1.0/sites?search=*&$select=id,displayName,webUrl
// For each site, check owners via:
GET /v1.0/sites/{site-id}/permissions6. Re-enable anonymization
PATCH https://graph.microsoft.com/v1.0/admin/reportSettings
{
"displayConcealedNames": true
}Deprovisioning actions (after manager approval)
// Remove a license
POST /v1.0/users/{upn}/assignLicense
{
"addLicenses": [],
"removeLicenses": ["{skuId}"]
}
// Block sign-in
PATCH /v1.0/users/{upn}
{
"accountEnabled": false
}
// Revoke all refresh tokens / sessions
POST /v1.0/users/{upn}/revokeSignInSessionsNote: Converting a mailbox to shared is available only through Exchange Online PowerShell (Set-Mailbox -Type Shared), not Graph.
PowerShell
Use the Microsoft.Graph PowerShell SDK to download the 90-day usage report, identify inactive users, enrich each with license and manager details, and output a CSV with deprovisioning recommendations.
Prerequisites
# Install once
Install-Module Microsoft.Graph -Scope CurrentUser
# Connect with required scopes
Connect-MgGraph -Scopes "Reports.Read.All","ReportSettings.ReadWrite.All","User.Read.All","Directory.Read.All"Approach
- Save the current
displayConcealedNamessetting so that you can restore it. - Disable report anonymization if needed.
- Retrieve the 90-day Office 365 active user detail report and parse the CSV.
- Filter for users where the latest activity across all services is older than 90 days (or never).
- For each match, retrieve the user and the user's manager to enrich the row with license count, manager, and department.
- Tag each row with a recommendation (for example
Review for license removal,Service account candidate, orExecutive - escalate to HR). - Export to CSV and restore the original anonymization setting.