Identify inactive mailboxes, usage drops, and licensed-but-unused accounts across your M365 tenant.
Complexity: Intermediate. Impact: cost-savings + license-optimization + security-monitoring + compliance + reporting.
Why use this workflow
Email activity reporting is a cornerstone of license right-sizing, offboarding hygiene, and security monitoring in Microsoft 365. Over time, mailboxes fall dormant: employees leave, roles shift, service accounts get forgotten. Their Exchange Online licenses continue to bill month after month.
When to run this workflow
- Quarterly license reviews: identify Exchange/E3/E5 seats that can be reclaimed or downgraded.
- Offboarding audits: confirm departed users' mailboxes are actually inactive before removal.
- Security investigations: a sudden drop in send/receive volume for a normally active user can indicate account compromise, forwarding rules, or delegation abuse.
- Adoption tracking: surface licensed users who never adopted Outlook, suggesting training gaps.
The Microsoft Graph reports/getEmailActivityUserDetail endpoint returns send, receive, and read counts per user over a rolling period (7, 30, 90, or 180 days). Joining this with the user/license directory in Entra ID produces a single spreadsheet that answers: who has a mailbox license but isn't using it?
Expected outcomes
After running this workflow, you will have:
- A CSV report listing every user with columns for display name, UPN, last activity date, 30-day send count, 30-day receive count, license status, and account-enabled state.
- A Status column classifying each user as Active, Low Activity / Potential Drop, Licensed - No Activity, or Inactive / No Data.
- A count of licensed users with zero email activity: the primary candidates for license reclamation.
- A reusable artifact suitable for sharing with finance, HR, or security for follow-up decisions.
Risks and considerations
Privacy and compliance
- Concealed names setting: If your tenant has "Display concealed user, group, and site names" enabled in the Microsoft 365 admin center, the report will return hashed UPNs (e.g.
A1B2C3...) instead of real email addresses, making the join with Entra ID impossible. Disable it temporarily (admin only) or accept anonymized output. - Reports.Read.All is powerful. It grants visibility into usage across all Microsoft 365 services. Scope app registrations carefully and rotate client secrets.
Data interpretation gotchas
- Report data is not real time. Microsoft states that the Email activity report in the admin center usually covers up to the last 24 to 48 hours, and that usage reports typically become available within 24 to 72 hours. A user active this morning may still appear inactive. Microsoft does not document a separate delay for the Graph
getEmailActivityUserDetailendpoint. - Users with only receive activity (e.g. distribution-list members) may look dormant but are still receiving business mail. Do not blindly remove their license.
- Shared mailboxes, resource mailboxes, and room mailboxes show up with inflated or unusual patterns. Filter
userTypeor recipient type separately. - New users in their first week typically have low counts. Exclude users created within the last 30 days before flagging.
Do not
- Do not auto-remove licenses based on this report alone. Always get manager or user confirmation.
- Do not share the CSV externally without redacting UPNs. It is personally identifiable data under GDPR/CCPA.
Required permissions
| Permission | Why it's needed |
|---|---|
| Reports.Read.All | Read usage reports including email activity detail via the Microsoft Graph reports endpoint. |
| User.Read.All | Enumerate users and retrieve assignedLicenses and accountEnabled properties to cross-reference with activity data. |
| Directory.Read.All | Optional: alternative to User.Read.All for broader directory read access. |
Ask Dex
Paste the prompt into a Dex conversation.
Prompt for IT admins
Pull email activity for the last {period_days} days across our M365 tenant. Identify inactive mailboxes, users with unusual drops in send/receive volume, and users who are licensed but have no email activity. Export the findings to a CSV report.
Manual steps (admin center)
The admin center exposes the same data the API returns, but with built-in charting and no need for app registration. This path is suited to one-off audits.
Step 1: Open the Email activity report
- Sign in to the Microsoft 365 admin center as a Global Reader, Reports Reader, or Global Administrator.
- Go to Reports > Usage > Email activity.
- Set the date range selector to Last 30 days (or 7/90/180 as needed).
Step 2: Confirm real names are visible
- If UPNs appear as hashes (e.g.
3F2504E0-...), go to Settings > Org settings > Services > Reports. - Uncheck Display concealed user, group, and site names in all reports.
- Click Save, then return to the report and refresh.
Step 3: Export and analyze
- On the Email activity report page, click the Export icon (down-arrow) in the top right.
- Open the downloaded CSV in Excel.
- Add a filter to the Last activity date column and sort ascending. Users with blank or oldest dates are your inactivity candidates.
- Cross-reference with Billing > Licenses to identify who is licensed but absent from the active list.
Step 4: Document findings
Tag each candidate with a disposition (reclaim license, convert to shared mailbox, investigate, leave alone) and circulate to the relevant business owners before making changes.
Microsoft Graph API
The Graph reports endpoint is the scriptable foundation of this workflow. It requires Reports.Read.All application or delegated permission.
Endpoint 1: Email activity detail (30 days)
GET https://graph.microsoft.com/v1.0/reports/getEmailActivityUserDetail(period='D30')Valid period values: D7, D30, D90, D180. The default response is CSV. To request JSON, append ?$format=application/json.
Sample CSV response (truncated)
Report Refresh Date,User Principal Name,Display Name,Is Deleted,Deleted Date,Last Activity Date,Send Count,Receive Count,Read Count,Meeting Created Count,Meeting Interacted Count,Assigned Products,Report Period
2025-01-15,alice@contoso.com,Alice Chen,False,,2025-01-15,42,187,203,3,11,MICROSOFT 365 E3,30
2025-01-15,bob@contoso.com,Bob Singh,False,,,,,,,MICROSOFT 365 E3,30Endpoint 2: User directory with licenses
GET https://graph.microsoft.com/v1.0/users?$select=id,displayName,userPrincipalName,assignedLicenses,accountEnabled&$top=999For tenants with more than 999 users, follow the @odata.nextLink cursor until exhausted.
Join logic
- Build a map keyed on lowercase UPN from the activity CSV.
- Iterate the user list. For each user, look up their activity row.
- Classify:
- Active: has
Last Activity Datewithin period and sendCount + receiveCount ≥ 5. - Low Activity: licensed, has activity row, but total < 5.
- Licensed - No Activity: licensed, no activity row or blank last activity date.
- Inactive / No Data: unlicensed and no activity.
- Active: has
Throttling
Graph throttles reports endpoints aggressively. If you receive 429 Too Many Requests, honor the Retry-After header. For tenants with more than 10,000 users, cache the activity CSV locally and reuse it across runs rather than re-fetching.
PowerShell
Prerequisites
- PowerShell 7.2 or later (Windows PowerShell 5.1 works but is slower).
- Microsoft Graph PowerShell SDK:
Install-Module Microsoft.Graph -Scope CurrentUser. - An account with Reports Reader + Directory Reader roles (or higher).
Approach
- Connect to Graph with the
Reports.Read.AllandUser.Read.Allscopes. - Download the email activity CSV for the requested period into a temp file.
- Page through
/users, collecting UPN, licenses, and enabled state. - Join on lowercase UPN and calculate a Status column.
- Write the merged result to an output CSV and print a summary table to the console.
Output columns
DisplayName, UserPrincipalName, Status, LastActivityDate, SendCount, ReceiveCount, ReadCount, IsLicensed, AccountEnabled, AssignedProducts.