The Get-MgUserMessage cmdlet in Microsoft Graph PowerShell retrieves email messages from a Microsoft 365 user’s mailbox. It allows administrators to fetch all messages, individual emails, or filtered sets of messages based on properties such as subject, sender, or received date.
This cmdlet is useful for:
By leveraging filters and search parameters, administrators can precisely extract the data they need instead of manually reviewing entire mailboxes.
Before using this cmdlet, connect to Microsoft Graph with the appropriate permissions:
Connect-MgGraph -Scopes "Mail.Read"
Syntax (essential parameters):
Get-MgUserMessage -UserId <String> [-MessageId <String>]
This cmdlet can be used to retrieve all messages for a user, fetch a single message by its ID, or apply filters for refined queries.
Get-MgUserMessage -UserId "john.doe@contoso.com"
This command retrieves all messages for the specified user.
Get-MgUserMessage -UserId "john.doe@contoso.com" -MessageId "AAMkAGI2T..."
This command retrieves a specific message by its message ID.
$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
This command retrieves messages with selected properties and displays them in a grid view.
Get-MgUserMessage -UserId "john.doe@contoso.com" -Filter "contains(subject,'Project Update')"
This command retrieves messages that contain “Project Update” in the subject.
Get-MgUserMessage -UserId "john.doe@contoso.com" -Search "Project Update"
This command searches for messages containing “Project Update.”
Get-MgUserMessage -UserId "john.doe@contoso.com" -Top 10
This command retrieves the top 10 messages for the specified user.
Get-MgUserMessage -UserId "user@domain.com" -Filter "from/emailAddress/address eq 'ceo@domain.com'" -Top 10
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