Script repository

Move mailbox to/from Microsoft 365

Updated on: Jan 18, 2026, Views: 5974

Exchange

The scripts are used to move a mailbox to or from Microsoft 365. To execute either of the scripts, create a business rule, custom command or scheduled task configured for the User object type.

Move mailbox from on-premises Exchange to Microsoft 365

Parameters

  • $remoteServer - the complete domain name of an externally accessible on-premises Exchange server that facilitates remote move migrations between Microsoft 365 and local Exchange. The on-premises Exchange server must have the Client Access role configured and the Mailbox Replication Service Proxy (MRSProxy) service running.
  • $targetDeliveryDomain - the name of a Microsoft 365 domain used for mail routing. After a mailbox is moved, the user becomes mail-enabled in local Exchange, and their mail is routed to the specified Microsoft 365 domain.
$remoteServer = "mail.mycompany.com" # TODO: modify me
$targetDeliveryDomain = "mycompany.mail.onmicrosoft.com" # TODO: modify me

# Move mailbox
$Context.TargetObject.CreateMoveMailboxToM365Request($remoteServer, $targetDeliveryDomain)

Move mailbox from Microsoft 365 to on-premises Exchange

Parameters

  • $targetDatabaseName - the name of the database in the on-premises Exchange server to move the mailbox to.
  • $remoteServer - the complete domain name of an externally accessible on-premises Exchange server that facilitates remote move migrations between Microsoft 365 and local Exchange. The on-premises Exchange server must have the Client Access role configured and the Mailbox Replication Service Proxy (MRSProxy) service running.
  • $targetDeliveryDomain - the on-premises target delivery domain. After a mailbox is moved, the user becomes mail-enabled in Microsoft 365, and their mail is routed to the specified domain.
$targetDatabaseName = "Mailbox Database 1" # TODO: modify me
$remoteServer = "mail.mycompany.com" # TODO: modify me
$targetDeliveryDomain = "mycompany.com" # TODO: modify me

# Move mailbox
$Context.TargetObject.CreateMoveMailboxFromM365Request($targetDatabaseName, $remoteServer, $targetDeliveryDomain)

Comments 0

You must be signed in to comment.

    Got questions?

    Support Questions & Answers

    We use cookies to improve your experience.
    By your continued use of this site you accept such use.
    For more details please see our privacy policy and cookies policy.