Automating New Mailbox Moves in Exchange Online

In a follow to my blog about finding a workaround to mailbox migrations in Office 365,

Workaround to Failing Migrations in Exchange Online

I had another challenge to be able to automate and do many users all at once to equal the features that migration batches would give me. If I couldn’t figure this out I would have considered this work around as not something I could permanently live with. I started out trying to call email addresses, but couldn’t figure out how to string it in the cmdlet so I ended up using alias instead.

The Solution

The first thing we need to do is define the variables we are going to use. I used $onprem to store my onpremise credentials, I wanted to ensure that the $alias variable started out as null, and $CSVFile will store the file of users I want to create/migrate mailboxes for.

$onprem = get-credential

$alias = $null

$CSVFile = import-csv -path c:\setup\bulkmig.csv

The second part is the command, I need to specificy that for each line in the CSV file I want to create a move request and the rest is just syntax and what options you want to use.

Foreach ($alias in $CSVFile) {New-MoveRequest -identity $alias.alias -Remote -RemoteHostName hybrid.cma.ca -RemoteCredential $onprem -TargetDeliveryDomain cmamdm.mail.onmicrosoft.com -baditemlimit unlimited

This now allows me to create a bulk migration of users and use the new-moverequest command to accomplish what was working in the GUI.

 

Leave a comment

Your email address will not be published.


*