Hybrid Exchange: User created - but mailbox is created in cloud due to script error - how to connect to identity

StephanG 811 Reputation points
2020-09-29T17:11:06.383+00:00

Hi,

i am just curious if this is working. We have hybrid setup and create AD users by script and then enable-remotemailbox.
But if the script fails the users gets a mailbox created in the cloud without a "hybrid identity" after the next sync and after assigning a license.

Is there any way to stop this behaviour or how can we connect an existing "cloud mailbox" to an onprem identity?

Best regards
Stephan

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,310 questions
0 comments No comments
{count} votes

Accepted answer
  1. KyleXu-MSFT 26,226 Reputation points
    2020-09-30T03:13:07.773+00:00

    @StephanG
    The "Enable-RemoteMailbox" will create a connection between Exchange on-premise and Exchange online. After that, it will not create a new mailbox in Exchange online when you assign license. Even if a new mailbox is created, it will connect with this remote mailbox automatically when the next synchronization because the relationship has exist.

    So, just make sure "Enable-RemoteMailbox" command was running successfully, the situation you are worried about will not happen.

    You can use script like below to check it(Or create a loop, the next step will be executed only if the command runs successfully):

    $resoult = Get-RemoteMailbox NewRemoteMailbox -ErrorAction SilentlyContinue  
    If ($resoult -ne $null){  
        #This remote mailbox created successfully  
        #Do the next step  
    }else{  
        #Not created successfully  
        #Bypass or checking in a loop  
    }  
    

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


1 additional answer

Sort by: Most helpful
  1. Andy David - MVP 143.7K Reputation points MVP
    2020-09-29T17:42:01.797+00:00

    To stop the behavior, do not add a license to a 365 account unless the remote mailbox is created and sycned. The script will need to have some steps in their to catch that when it fails.

    Alternatively, In this scenario, you can still create a remote mailbox after the fact. It will provision it and will link to the on-prem account based on the source anchor.
    https://learn.microsoft.com/en-us/azure/active-directory/hybrid/plan-connect-design-concepts

    After you create the remote mailbox, get the ExchangeGuid of the mailbox in Office 365 following this article:

    https://support.microsoft.com/en-us/help/2956029/migrationpermanentexception-cannot-find-a-recipient-that-has-mailbox-g

    Connect to Exchange Online Powershell:

    Get-Mailbox <MailboxName> | Format-List ExchangeGUID   
    

    Run the following command to set the value of the ExchangeGUID property on the on-premises remote mailbox to the value that you retrieved above

    Set-RemoteMailbox <MailboxName> -ExchangeGUID <GUID>   
    

    Force directory synchronization.

    Thats it. You are done!