You can use the New-InboxRule
command in PowerShell to create a mailbox rule on a shared mailbox in Office 365. However, the New-InboxRule
command requires the use of the -Mailbox
parameter to specify the mailbox to which the rule should be applied.
When you try to create a rule on a shared mailbox using New-InboxRule
command, you receive "Cannot open mailbox" error, because the New-InboxRule
command can't be used directly on a shared mailbox, you need to use the -Mailbox
parameter to specify the mailbox to which the rule should be applied.
You can use the below command to create a mailbox rule on a shared mailbox to move all incoming email coming from externaluser01 to the junkfolder on sharedmailbox01
New-InboxRule -Name "Rule for Externaluser01" -Mailbox sharedmailbox01 -From externaluser01@example.com -MoveToFolder JunkEmail
Make sure you have the correct permissions to create a rule on a shared mailbox, You need the "Organization Management" role or "Full Access" permission to the shared mailbox.
You can also use the Get-MailboxPermission
command to check the permissions on the shared mailbox, and Add-MailboxPermission
command to add the necessary permissions if you don't have them.
Get-MailboxPermission -Identity sharedmailbox01
Add-MailboxPermission -Identity sharedmailbox01 -User <user> -AccessRights FullAccess
Please note that the above commands should be executed on Exchange Online PowerShell and not on the local PowerShell.