Efficient email management often requires moving messages between folders within a user's mailbox. The Move-MgUserMessage cmdlet in Microsoft Graph PowerShell enables administrators to move messages seamlessly. This article covers the cmdlet's syntax, usage examples, tips, use cases, possible errors, and their solutions.
Move-MgUserMessage -UserId <String> -MessageId <String> -BodyParameter <Hashtable>
Note: To move messages between folders, you need the folder ID, which can be got using Get-MgUserMailFolder cmdlet.
$params = @{
DestinationId = "AQMkAGI2TAAA="
}
Move-MgUserMessage -UserId "user@domain.com" -MessageId "AAMkADhZD3KZAAA=" -BodyParameter $params
$messages = @("AAMkADhZD3KZAAA=", "AAMkADhZD3KZAAQ=")
$destination = @{
DestinationId = "AQMkAGI2TAAA="
}
foreach ($messageId in $messages) {
Move-MgUserMessage -UserId "user@domain.com" -MessageId $messageId -BodyParameter $destination
}
$oldMessages = Get-MgUserMessage -UserId "user@domain.com" -Filter "receivedDateTime lt 2023-01-01"
$destination = @{
DestinationId = "AQMkAGI2TAAA="
}
foreach ($message in $oldMessages) {
Move-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id -BodyParameter $destination
}
$folderMessages = Get-MgUserMessage -UserId "user@domain.com" -MailFolderId "AQMkADhZD3KZAAAA=" -All
$destination = @{
DestinationId = "AQMkAGI2TAAA="
}
foreach ($message in $folderMessages) {
Move-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id -BodyParameter $destination
}
Cause: The specified UserId does not exist.
Solution: Verify the UserId and ensure the user exists in the tenant.
Cause: The specified MessageId or DestinationId does not exist.
Solution: Verify the MessageId and DestinationId and ensure they exist in the user's mailbox.
Cause: Invalid parameters passed to the cmdlet.
Solution: Ensure the BodyParameter is correctly formatted and contains valid keys.
Cause: Insufficient permissions to move the message.
Solution: Ensure the executing account has the necessary permissions to move messages in the specified mailbox.
1. What is Move-MgUserMessage used for?
Move-MgUserMessage is a Microsoft Graph PowerShell cmdlet used to move email messages from one folder to another in a user’s mailbox.
2. How can I move a single email message to another folder?
Use the following command to move a specific message:
Move-MgUserMessage -UserId "<UserPrincipalName>" -MessageId "<MessageId>" -DestinationId "<DestinationFolderId>"
3. Can I move multiple messages to another folder?
Yes, retrieve messages using a query or filter and then move them in a loop. Example:
$Messages = Get-MgUserMessage -UserId "<UserPrincipalName>" -Filter "isRead eq false"
foreach ($Message in $Messages) {
Move-MgUserMessage -UserId "<UserPrincipalName>" -MessageId $Message.Id -DestinationId "<DestinationFolderId>"
}
4. What permissions are required to use Move-MgUserMessage?
You need the Mail.ReadWrite permission in Microsoft Graph PowerShell. Ensure these permissions are granted in Azure AD.
The Move-MgUserMessage cmdlet is a powerful tool for organizing and managing emails within Microsoft 365 mailboxes. By understanding its syntax, usage examples, and potential errors, IT administrators can efficiently move messages, ensuring mailboxes remain organized and manageable.
© m365corner.com. All Rights Reserved. Design by HTML Codex