Script Repository


Create remote mailbox

June 20, 2019
4669

The script can be used in Business Rules, Custom Commands or Scheduled Tasks to create a remote mailbox for a user. For example, to create remote mailboxes for new users, you need to create a Business Rule that automatically runs the script once a new user is created. For more information, see Run PowerShell Script after Creating a User.

Script 1: For Adaxes 2016 and later

In the script, the $remoteRoutingAddressTemplate variable specifies a template for the Remote Routing Address which will be applied to the remote mailbox. You can use value references in the template (e.g. %username%)

Edit Remove
PowerShell
$remoteRoutingAddressTemplate = "%username%@mycompany.mail.onmicrosoft.com" # TODO: modify me

$Context.TargetObject.EnableRemoteMailbox($remoteRoutingAddressTemplate)

Script 2: For Adaxes 2015 and earlier

Parameters:

  • $exchangeServer - specifies the fully qualified domain name (FQDN) of the Exchange Server that will be used to create mailboxes;
  • $o365Domain - specifies the the email domain of the Exchange Online service that the mailbox will be associated with.
Edit Remove
PowerShell
$exchangeServer = "exchangeserver.example.com" # TODO: modify me
$o365Domain = "domain.mail.onmicrosoft.com" # TODO: modify me

try
{
    # Connect to Exchange Server
    $session = New-PSSession -Configurationname Microsoft.Exchange –ConnectionUri http://$exchangeServer/powershell
    Import-PSSession $session -DisableNameChecking -AllowClobber

    # Create remote mailbox
    Enable-RemoteMailbox "%distinguishedName%" -RemoteRoutingAddress "%samaccountname%@$o365Domain"
}
finally
{
    # Close connection to Exchange Server
    Remove-PSSession $session
}


Comments ( 2 )
avatar
ComputerHabit
Aug 18, 2020
Script 1 doesn't seem to work in a hybrid situation.
avatar
Support
Aug 19, 2020

Hello,

What script are you using, For Adaxes 2015 and earlier or For Adaxes 2016 and later? How exactly do you execute the script? Do you face any error messages? If you do, please, provide us with screenshots. Screenshots of the workflow setup will be very helpful.

Also, it is not required to use scripts to enable remote mailboxes, it can be done automatically when a Microsoft 365 license is assigned to a user. For details, have a look at the following help article: https://www.adaxes.com/help/?HowDoI.PerformExchangeTasks.ConfigureEnablingDisablingOfRemoteMailboxes.html.

Leave a comment

Related Scripts