Search code examples
powershellexchange-serverhybrid

Cannot add or remove mailaddress with Powersshell in Exchange Hybrid neither OnPremise nor on Exchange Online


I am running a Hybrid Exchange Server installation. AD is synced to Azure and most of the mailboxes are in the cloud, not on Premise.

Now I am not able to add or remove an email address from a users mailbox.

The recommended way to do this reading the Micorsoft docs is

Set-Mailbox -Identity <identity> -EmailAddresses @{add='[email protected]'}

Unfortunately this leads to an error:

Microsoft.Exchange.Configuration.DualWrite.LocStrings.UnableToWriteToAadException|An Azure Active Directory call was made to keep object in sync between Azure Active Directory and Exchange Online. However, it failed.

Detailed error:

Unable to update the specified properties for on-premises mastered Directory Sync objects or objects currently undergoing migration. DualWrite (Graph)

Well trying to run this at the on Premise machine, it leads to this error:

The operation couldn't be performed because object 'identity' couldn't be found on 'domaincontroller.domain.com'.

This seems to be ok, since the mailbox is not at the On Premise server. Beeing true, I am also a little bit confused about user, usermailbox, mailbox, recipient, ...

Can anyone give me a hint how to fix this and how to add/remove a mail adress from a user?

Finally I found out, that it is not possible to change the mailaddresses at the cloud in a Hybrid environment. You get the same error, if you try this in the exchange online admin center, and this is by default.

In a Hybrid environment the mailadresses have to be set On Premise. This works in the admin center of the On Premise machine, but I found no way to do it with powerhell, since the "object is not found" error occurs.

So how to get the O365 Mailbox of a user On Premise?


Solution

  • From the On-Premises-Exchangeserver's view, the object is not a mailbox, but a RemoteMailbox Therefore I have to use the Set-RemoteMailbox Cmdlet, instead of Set-Mailbox

    Set-RemoteMailbox -Identity <identity> -EmailAddresses @{add='[email protected]'}
    

    and

    Set-RemoteMailbox -Identity <identity> -EmailAddresses @{remove='[email protected]'}
    

    works for adding and removing mail addresses from these mailboxes. Thanks to Evgenij Smirnov, who pointed me in the right direction.

    (Link is German language only ) https://social.technet.microsoft.com/Forums/de-DE/320866b5-cf71-452c-ba65-8f331857eb64/hinzufgen-oder-lschen-einer-email-adresse-in-hybrid-umgebung-mit-powershell?forum=exchange_serverde