Create mailbox rule in Powershell?

Keith Hampshire 96 Reputation points
2023-01-19T18:15:12.8133333+00:00

We are using O365 for email. How can I create a mailbox rule on a Shared mailbox using PowerShell? We are having an issue with certain outside senders emailing to our shared mailbox over and over again. I want to have those senders moved to the Junk Email folder. I do not want to create a mailflow rule that blocks it because we want to have record of it.

If I use the "New-Inboxrule" command I receive an error message stating "Cannot open mailbox".

Have do I move (via a rule) all incoming email coming from externaluser01 to the junkfolder on sharedmailbox01?

Exchange Online
Exchange Online
A Microsoft email and calendaring hosted service.
6,171 questions
0 comments No comments
{count} votes

Accepted answer
  1. Amit Singh 5,306 Reputation points
    2023-01-20T05:23:39.8266667+00:00

    If you want access to all mailboxes, then use the below.

    Get-Mailbox -ResultSize unlimited -Filter {(RecipientTypeDetails -eq 'UserMailbox')} | Add-MailboxPermission -User "yoursmtpaddress" -AccessRights FullAccess -InheritanceType all -AutoMapping:$false

    Just to confirm, this command will give you full access on all mailboxes.

    To create the custom folder, you can follow the below article.

    https://social.technet.microsoft.com/wiki/contents/articles/14515.create-a-custom-root-folder-in-all-the-mailboxes-bulk-in-exchange-2010.aspx

    0 comments No comments

5 additional answers

Sort by: Most helpful
  1. Shelton, Vincent 0 Reputation points
    2024-09-25T12:37:16.7766667+00:00

    Hello Everyone,

    My name is Robert. I have granted myself full mailbox permissions to my mailbox using my Office 365 tenant account. I am getting this error. See below.

    Write-ErrorMessage : Ex40A70F|Microsoft.Exchange.Data.Common.LocalizedException|Folder Inbox\Quarantine doesn't belong to vshelton. You cannot move it.

    At C:\Users\vshelton\AppData\Local\Temp\tmpEXO_emeghob4.rkd\tmpEXO_emeghob4.rkd.psm1:1205 char:13

    •         Write-ErrorMessage $ErrorObject
      
    •         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      
      • CategoryInfo : InvalidOperation: (:) [New-InboxRule], LocalizedException
      • FullyQualifiedErrorId : [Server=DS7PR01MB7880,RequestId=062c6666-b6db-a6df-0d58-4672ea3ed75a,TimeStamp=Wed, 25 Sep 2024 12:24:24 GMT],Write-ErrorMessage
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.