fbpx

Mailbox migration in a Hybrid Exchange Environment (PowerShell)

Here is how we can perform a remote move (onprem to cloud) using PowerShell.

Firstly, you would have to import your Exchange Online module.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

Now you will be prompted for username and password,


However, if you would like to skip the hassle you can add a couple line of codes.

$pwd= ConvertTo-SecureString “xxxxx” -AsPlainText -force

$UserCredential = New-Object System.Management.Automation.PSCredential (“your@email.com”, $pwd)

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection

Import-PSSession $Session

 

Now that you have imported Exchange Online, you can start the migration or what I would prefer to call it, “moverequest”.

 

$ONPREMCREDS = Get-Credential <your onprem admin credential, domainaccountname>

New-MoveRequest -Identity “mailbox name” -Remote -RemoteHostName <name of your hybrid connection> -TargetDeliveryDomain <your target delivery domain, xxx@mail.onmicrosoft.com> -RemoteCredential $ONPREMCREDS -BadItemLimit 10

Once you had initiated a move request you can proceed to view the progress.

Get-moverequest

So, we had covered how to remotely transfer a mailbox from onprem to cloud. What about the other way around?

$opcred = get-credential <your onprem admin crendential>

Get-Mailbox -Identity “mailbox you want to move back to onprem” | New-MoveRequest -OutBound -RemoteTargetDatabase “name of your onprem database” -RemoteHostName “name of your hybrid connection” -RemoteCredential $opcred -TargetDeliveryDomain “your target delivery domain”

Leave a Reply

Your email address will not be published.