Powershell – Office365: Error trying to create Inbox Rule via PowerShell

mailboxmicrosoft-office-365powershellrules

In our Office365 environment I'm trying to programmatically create rules that will move incoming messages based on the distribution list they were received as.

However, while prototyping, the following command consistently creates an error:

New-InboxRule -Mailbox alias -Name RuleName -SentTo smtp.address@of.distribution.list -MoveToFolder \Archive\DLName

The error is:

WARNING: An unexpected error has occurred and a Watson dump is being generated: The operation can't be performed on this object because its status isn't valid.

What object is being referred to here? And where can I see that Watson dump and will it be of any use?

The target folder does exist.

Should I maybe refer to any of the involved parts (mailbox, recipient, folder) using a different syntax?

  • Get-Mailbox alias correctly returns the intended mailbox object so that seems to be fine… (I did also try with the full SMTP-address of that mailbox)
  • Get-Recipient smtp.address@of.distribution.listcorrectly resolved the intended recipient object so that seems to be fine…

The most likely culprit for me right now appears to be the target folder. If I change the syntax to mailbox-alias:\Path\To\Target or mailbox-smtp-address:\Path\To\Target then I get a "Cannot open mailbox" error instad of the above. Is it possible that when I leave out the name of the mailbox it will look for that folder path inside my admin user's mailbox? That would have to fail, as the admin user does not actually have a mailbox in the first place…
If that is it, how else should I reference the folder?

Additional Information:

  • The mailbox I'm trying to add this rule to is (currently) a regular user mailbox but will likely be converted to a shared mailbox eventually.
  • We have not yet completed our migration to Office365, so the MX record for our SMTP domain has not yet been adjusted to point at Exchange Online directly. However, inside the successfully connected PowerShell session, DNS shouldn't be an issue, or should it? In any case, I already tried all of the above with the respective *.onmicrosoft.com addresses as well.
  • As I mention the ongoing migration: The mailbox in question has not been migrated, but rather was created from scratch.
  • Creating the rule completely manually inside Outlook works flawlessly and I can also query its properties using Get-InboxRule -Mailbox alias

Best Answer

I finally managed to script the rule creation. Apparently, the admin user account that is running the script has to...:

  • have a mailbox of their own (=> requires an Office365 license, particularly an Exchange Online license)
  • have full access permission on the target mailbox

As far as I was able to tell, it is also necessary to grant the Full Access permission directly to the respective user. Granting it indirectly via group membership did not work.

Previously my admin user did not have an Office365 license assigned and thus also did not have explicit permissions on the mailbox.