The Copy-MgUserMessage cmdlet in Microsoft Graph PowerShell is a powerful tool that allows administrators to copy email messages from one folder to another within a user's mailbox. This cmdlet is particularly useful for managing and organizing emails in bulk or based on specific conditions.
Note: You need mail folder ID and message ID to work with this cmdlet. Use Get-MgUserMailFolder and Get-MgUserMailFolderMessage cmdlets to get the IDs.
Copy-MgUserMessage -UserId <String> -MessageId <String> -DestinationId <String> [-WhatIf] [-Confirm]
This example copies a single email message with the specified MessageId from the user's mailbox to the destination folder identified by DestinationId.
Copy-MgUserMessage -UserId "user@domain.com" -MessageId "AAMkAG..." -DestinationId "AQMkAG..."
This example copies multiple messages by iterating through an array of MessageId values and copying each one to the specified destination folder.
$messageIds = @("AAMkAG...", "AAMkBG...")
foreach ($id in $messageIds) {
Copy-MgUserMessage -UserId "user@domain.com" -MessageId $id -DestinationId "AQMkAG..."
}
This example retrieves messages with a specific subject using the Get-MgUserMessage cmdlet and then copies those messages to the desired folder.
$messages = Get-MgUserMessage -UserId "user@domain.com" -Filter "subject eq 'Important'"
foreach ($message in $messages) {
Copy-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id -DestinationId "AQMkAG..."
}
This example copies all messages from a user's mailbox to another folder.
$allMessages = Get-MgUserMessage -UserId "user@domain.com" -All
foreach ($message in $allMessages) {
Copy-MgUserMessage -UserId "user@domain.com" -MessageId $message.Id -DestinationId "AQMkAG..."
}
Cause: The MessageId provided does not exist in the user's mailbox.
Solution: Verify that the MessageId is correct. You can use the Get-MgUserMessage cmdlet to list messages and confirm the ID.
Cause: The DestinationId does not correspond to a valid folder in the user's mailbox.
Solution: Ensure that the DestinationId is accurate. You can use Get-MgUserMailFolder to retrieve and verify folder IDs.
Cause: The account running the cmdlet lacks the necessary permissions to copy messages.
Solution: Confirm that the account has the required permissions. The user might need the Mail.ReadWrite permission.
Cause: The operation took too long to complete, possibly due to the large number of messages.
Solution: Break down the operation into smaller batches or optimize the message retrieval process.
The Copy-MgUserMessage cmdlet is a versatile tool in the Microsoft Graph PowerShell module that simplifies email management within user mailboxes. By leveraging this cmdlet, administrators can efficiently handle various tasks such as bulk copying, filtering, and organizing emails, ensuring smooth operations and adherence to compliance requirements. Understanding the cmdlet's syntax, potential errors, and use cases will enable you to make the most of its capabilities in your day-to-day administrative tasks.
© m365corner.com. All Rights Reserved. Design by HTML Codex