How to Use Get-MgUserMessage to Fetch User Mails?

When managing Microsoft 365 environments, administrators often need to audit or fetch users' emails for troubleshooting, compliance, or reporting. The Get-MgUserMessage cmdlet from Microsoft Graph PowerShell makes this task seamless by letting you retrieve email messages directly from users’ mailboxes.

In this guide, we'll explore why and how to use this cmdlet, walk through practical examples, and highlight real-world use cases.


What is Get-MgUserMessage?

Get-MgUserMessage is a Microsoft Graph PowerShell cmdlet used to fetch messages from a specific user’s mailbox. Whether you want to view the latest emails, retrieve specific messages, or extract only certain fields, this cmdlet has you covered.


Why Use Get-MgUserMessage?

Here are a few reasons admins prefer this cmdlet:

  • Audit mailbox activity for compliance or security reviews.
  • Search emails containing specific subjects or phrases.
  • Export important metadata like sender, recipients, and timestamps.
  • Assist end users in locating or troubleshooting missing emails.

Cmdlet Syntax

Get-MgUserMessage -UserId  [-MessageId ] [-Top ] [-Filter ] [-Search ] [-Property ] [-All] []

UserId is the only mandatory parameter. It refers to the user's UPN (email address) or user ID.


Usage Examples

  1. Retrieve All Messages for a User
  2. Get-MgUserMessage -UserId "john.doe@contoso.com"

    This retrieves the first page of messages from the user's inbox.

  3. Retrieve a Specific Message by Message ID
  4. Get-MgUserMessage -UserId "john.doe@contoso.com" -MessageId "AAMkAGI2T..."

    Useful for retrieving the full message details using its unique identifier.

  5. Retrieve Messages with Specific Properties
  6. Extracting subject, sender, received date, and recipient info in a grid view:

    $User = "samadmin@7xh7fj.onmicrosoft.com"
    Get-MgUserMessage -All -UserId "$User" |
    Select-Object Subject, InternetMessageId, ReceivedDateTime,
    @{Name = "Sender"; Expression = { $_.Sender.EmailAddress.Address }},
    @{Name = "Recipients"; Expression = { $_.ToRecipients.EmailAddress.Address -join ' ' }} |
    Out-GridView
                                                

    Perfect for exporting summarized message data.

  7. Filter Messages by Subject
  8. Get-MgUserMessage -UserId "john.doe@contoso.com" -Filter "contains(subject,'Project Update')"

    Fetches only the emails with “Project Update” in the subject line.

  9. Search Messages
  10. Get-MgUserMessage -UserId "john.doe@contoso.com" -Search "Project Update"

    Searches across multiple properties (subject, body, etc.) for the phrase "Project Update".

  11. Retrieve a Limited Number of Messages
  12. Get-MgUserMessage -UserId "john.doe@contoso.com" -Top 10

    Fetches the 10 most recent messages.


Frequently Asked Questions

  • Can I access messages from a shared mailbox using this cmdlet?
    Yes, as long as you have permission and know the User ID (UPN or object ID) of the shared mailbox.
  • What’s the difference between -Filter and -Search?
    -Filter applies to specific fields (like subject, receivedDateTime, etc.), whereas -Search performs a broader, full-text search across the message content.
  • What’s the limit on messages retrieved without -All?
    By default, only a page of messages is returned (usually 100). Use -All to fetch everything.

Use Cases

  • Security Investigation: Fetch emails from or to suspicious domains.
  • Compliance Checks: Verify whether specific emails were received/sent.
  • Automation: Use scripts to regularly pull specific message metadata.
  • User Support: Help users find lost or misfiled emails.

Conclusion

Get-MgUserMessage is a powerful tool that brings transparency and control to Microsoft 365 email management. With a few lines of PowerShell, you can pull critical email data, filter through messages, and extract meaningful insights from user mailboxes.

Whether you're auditing, troubleshooting, or automating reporting tasks, this cmdlet deserves a spot in your admin toolkit.

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