Get-MgUserMessageCount is a Microsoft Graph PowerShell cmdlet used to retrieve the total number of email messages in a user’s mailbox. Instead of returning full message objects, this cmdlet efficiently returns only the count, making it ideal for reporting and analytics.
It supports OData filters, allowing administrators to count messages based on conditions such as read status, folder, or date range.
Try the M365Corner Microsoft 365 Reporting Tool — your DIY pack with 20+ out-of-the-box M365 reports for Users, Groups, and Teams.
Administrators use Get-MgUserMessageCount to:
This cmdlet is especially useful for lightweight reporting and automation dashboards.
Before using this cmdlet, ensure:
Connect-MgGraph -Scopes "Mail.Read"
Basic syntax:
Get-MgUserMessageCount -UserId <String> [-Filter <String>]
Get-MgUserMessageCount -UserId "user@domain.com"
This example retrieves the total count of messages in the specified user's mailbox.
Get-MgUserMessageCount -UserId "user@domain.com" -Filter "isRead eq false"
This example retrieves the count of unread messages in the user's mailbox
Get-MgUserMessageCount -UserId "user@domain.com" -Filter "parentFolderId eq 'AAMkAGI2TAAA='"
This example retrieves the count of messages in a specific mail folder using its folder ID. Use the Get-MgUserMailFolder cmdlet to retrieve the folder ID.
Get-MgUserMessageCount -UserId "user@domain.com" `-Filter "receivedDateTime ge 2023-01-01T00:00:00Z and receivedDateTime le 2023-12-31T23:59:59Z"
This example retrieves the count of messages received within a defined date range.
| Cmdlet | Purpose | Output | When to Use |
| Get-MgUserMessageCount | Returns the number of messages in a mailbox | Integer (count only) | When you only need statistics, trends, or quick counts |
| Get-MgUserMessage | Retrieves full email message objects | Message details (subject, sender, body, etc.) | When you need to read, move, copy, or analyze messages |
Key Difference
| Key Point | Details |
| Cmdlet Name | Get-MgUserMessageCount |
| Purpose | Retrieves message count from a user mailbox |
| Required Scope | Mail.Read |
| Data Returned | Integer count only |
| Supports Filters | Yes (OData) |
| Performance | High (no message objects returned) |
| Common Use Cases | Reporting, analytics, mailbox monitoring |
Did You Know? Managing Microsoft 365 applications is even easier with automation. Try our Graph PowerShell scripts to automate tasks like generating reports, cleaning up inactive Teams, or assigning licenses efficiently.
Ready to get the most out of Microsoft 365 tools? Explore our free Microsoft 365 administration tools to simplify your administrative tasks and boost productivity.
© Your Site Name. All Rights Reserved. Design by HTML Codex