Broken link between on-prem Exchange and Office 365 mailbox

How to fix an on-prem users connection to their Office 365 in hybrid environments.

Broken link between on-prem Exchange and Office 365 mailbox
Photo by Brett Jordan / Unsplash

Just recently we received a ticket stating that a user needed to be added as a delegate to a shared mailbox in Office 365.

Both the user and the shared mailbox were both mastered on the on-prem domain, and then sync'd to Azure AD using Azure AD Connect.

The problem was that the user did not appear in the on-prem Exchange in order to grant them access to the mailbox.

To fix this, I put together the following script:

[CmdletBinding()]
param (
	[Parameter()]
    [string]
    $UserName,
    
    [Parameter()]
    [string]
    $EmailAddress,
    
    [Parameter()]
    [string]
    $OnPremExchangeServer
)

# Connect
Connect-ExchangeOnline -Prefix "o"

$LocalExSession = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionURI "http://$($OnPremExchangeServer)/PowerShell
Import-PSSesssion $LocalExSession -Prefix "l" -AllowClobber

# enable the remote mailbox
Enable-lRemoteMailbox $UserName -RemoteRoutingAddress $EmailAddress

# get remote mailbox
$oMailbox = Get-oMailbox -Identity $EmailAddress

# set remote mailbox on local object
Set-lRemoteMailbox $UserName -ExchangeGUID $($oMailbox.ExchangeGUID)

This adds the Exchange Online commands to the current PowerShell session - all prefixed wtih the letter "o", and also adds all the on-prem Exchange commands to the PowerShell session prefixed with the letter "l". The prefix switch makes it easy to work with two PowerShell modules that have overlapping commands.