Simplify user tasks like bulk creation, updates, password resets, deletions, license checks & more — all from one place.
🚀 Launch ToolkitMonitoring mailbox activity is a vital part of Microsoft 365 administration. Whether you're auditing inactive users or analysing mailbox usage trends, PowerShell—combined with Microsoft Graph—offers a powerful approach.
In this article, we’ll walk you through how to retrieve user mailbox activity using the Get-MgReportMailboxUsageDetail cmdlet from the Microsoft Graph PowerShell module.
# Connect to Microsoft Graph with Reports.Read.All permission
Connect-MgGraph -Scopes "Reports.Read.All"
# Fetch mailbox usage details for the last 30 days (maximum retention: 180 days)
$response = Get-MgReportMailboxUsageDetail -Period "D30"
# Display mailbox activity
if ($response.Count -eq 0) {
Write-Host "No mailbox data available for the selected period." -ForegroundColor Yellow
} else {
$response | Select-Object `
@{Name = "Display Name"; Expression = { $_.DisplayName }},
@{Name = "User Principal Name"; Expression = { $_.UserPrincipalName }},
@{Name = "Is Licensed"; Expression = { if ($_.IsLicensed -eq $true) { "Licensed" } else { "Unlicensed" } }},
@{Name = "Last Activity Date"; Expression = { $_.LastActivityDate }},
@{Name = "Mailbox Size (MB)"; Expression = { $_.StorageUsedInMB }} |
Format-Table -AutoSize
}
Here are a few ideas to expand this script:
If you see placeholder values or anonymized data (like numeric strings) in the UserPrincipalName field, you need to disable privacy settings in the Microsoft 365 Admin Center:
🔁 You may need to wait up to 24 hours for changes to reflect in usage reports.
You’ll need the Reports.Read.All or Reports.ReadWrite.All permission in Microsoft Graph. These can be granted either through delegated or application permissions depending on your access model.
The mailbox activity reports depend on the Microsoft 365 reporting data refresh cycle. If users haven’t accessed their mailboxes during the specified period, the data may appear empty. Try expanding the report period to D30 or D90.
Yes. You can schedule a PowerShell script that runs the Get-MgReportMailboxUsageDetail cmdlet daily or weekly and exports results to a CSV for automated reporting and trend tracking.
The Period parameter supports a maximum of 180 days (D180). Any request beyond that limit will return an error.
| Error | Cause | Solution |
| Access Denied | Missing Graph permissions | Use Connect-MgGraph -Scopes "Reports.Read.All" |
| Blank UserPrincipalName | Privacy settings enabled | See the note above to show real UPNs |
| The term 'Get-MgReportMailboxUsageDetail' is not recognized | Module not installed or outdated | Run Install-Module Microsoft.Graph.Reports |
-Period parameter in Get-MgReportMailboxUsageDetail lets you specify how far back you want to retrieve mailbox activity — such as D7, D30, D90, or D180.-OutFile parameter to export your mailbox usage reports to CSV format. This makes it easy to perform offline analysis, visualize trends, or share data across teams.Get-MgReportMailboxUsageDetail -Period D30 -OutFile "C:\Reports\MailboxUsage.csv"
The Get-MgReportMailboxUsageDetail cmdlet is a reliable way to monitor mailbox activity across your Microsoft 365 environment. With just a few lines of code, administrators can generate useful reports, identify inactive mailboxes, and ensure efficient use of licenses. As Microsoft Graph evolves, keep an eye out for more flexible reporting endpoints that may allow direct querying and filtering in JSON.
© m365corner.com. All Rights Reserved. Design by HTML Codex