In the process of migrating our mailboxes from our on-premise Exchange servers to Office 365, we had to rewrite the mailbox enable scripts. This script keys off of our HR database, does some magic, then calls
Enable-Mailbox on Exchange 2010 servers. To update this to support creating mailboxes in Office 365, we needed to set user licenses, and use the
Enable-RemoteMailbox command in Exchange 20131.
One of the quirks we stumbled upon is a bug in the Exchange 2013 tools that didn’t allow it to identify the domain for the remote routing address. This is what we’d get:
[PS] C:\ > Enable-RemoteMailbox Jonathan.Angliss The address '@mytenant.mail.onmicrosoft.com' is invalid: "@mytenant.mail.onmicrosoft.com" isn't a valid SMTP address. The domain name can't contain spaces and it has to have a prefix and a suffix, such as example.com. + CategoryInfo : NotSpecified: (:) [Enable-RemoteMailbox], DataValidationException + FullyQualifiedErrorId : [Server=Exchsvr01,RequestId=190c9764-d8bd-446e-ac43-7c80bcc54eea,TimeStamp=6/3/2014 1:19:33 PM] [FailureCategory=Cmdlet-DataValidationException] 730D5E7F,Microsoft.Exchange.Management.RecipientTasks.EnableRemoteMailbox + PSComputerName : Exchsvr01
According to the Microsoft documentation for
Enable-RemoteMailbox you should be able to specify just the sAMAccountName as an argument, the rest should be calculated.
The remote routing address doesn’t need to be specified because mail flow between the on-premises organization and the service has been configured. Using this configuration, the Enable-RemoteMailbox cmdlet automatically calculates the SMTP address of the mailbox to be used with the RemoteRoutingAddress parameter. — Microsoft TechNet
This apparently isn’t the case, so some tweaking was needed. We called upon
Get-ADUser to retreive the account, and fill in the rest.
[PS] C:\ > Get-ADUser jonathan.angliss | Enable-RemoteMailbox $_.sAMAccountName -RemoteRoutingAddress "$($_.sAMAccountName)@mytenant.mail.onmicrosoft.com"
As this is part of a script, the content is slightly different, but you can see how it works. We used
Get-ADUser earlier in the script to pull other user data to calculate licensing requirements, but if you’re doing this as a one off and are seeing the error then you could just as easily do this:
[PS] C:\ > Enable-RemoteMailbox jonathan.angliss -RemoteRoutingAddress '[email protected]'
Hat tip goes to Steve Goodman for posting similar work, and getting me back on track.
If you are using a 2010 Exchange environment, you need a 2013 server to act as a Hybrid server to migrate users. ↩