The New-MgUserMailFolderMessageRule cmdlet is part of the Microsoft Graph PowerShell module, enabling administrators to create new message rules within a user's mail folder. These rules can help automate email management by applying specific actions to messages that meet defined criteria. This article provides a detailed overview of the cmdlet, including syntax, usage examples, tips, use cases, and potential errors with solutions.
Note: Mail.ReadWrite is the Graph API permission you need to execute this cmdlet.
New-MgUserMailFolderMessageRule -UserId <String> -MailFolderId <String> -BodyParameter <Hashtable>
$params = @{
displayName = "Forward Emails from Gmail"
sequence = 1
conditions = @{
senderContains = @("gmail.com")
}
actions = @{
forwardTo = @(
@{
emailAddress = @{
name = "Another User"
address = "anotheruser@domain.com"
}
}
)
stopProcessingRules = $true
}
}
New-MgUserMailFolderMessageRule -UserId "samadmin@7xh7fj.onmicrosoft.com" -MailFolderId "Inbox" -BodyParameter $params
$params = @{
displayName = "Mark Sale Emails as Read"
sequence = 2
conditions = @{
subjectContains = @("Sale")
}
actions = @{
markAsRead = $true
stopProcessingRules = $true
}
}
New-MgUserMailFolderMessageRule -UserId "samadmin@7xh7fj.onmicrosoft.com" -MailFolderId "Inbox" -BodyParameter $params
Cause: Incorrect or missing required properties in the -BodyParameter hashtable.
Solution: Ensure all required properties are correctly specified in the hashtable. Refer to the Microsoft documentation for details.
Cause: The moveToFolder action specifies a folder path that does not exist.
Solution: Verify that the specified folder path is correct and that the folder exists in the user's mailbox.
Cause: The -UserId parameter specifies a user that does not exist.
Solution: Ensure the user ID or UPN specified in the -UserId parameter is correct and that the user exists in the tenant.
The New-MgUserMailFolderMessageRule cmdlet is a powerful tool for automating email management within a user's mailbox. By creating custom rules, administrators can help users maintain an organized and efficient inbox. Understanding the cmdlet's syntax, usage, and potential errors ensures successful implementation. For further details, refer to the official Microsoft documentation.
© m365corner.com. All Rights Reserved. Design by HTML Codex