Bulk Enabling Mailboxes from a CSV and Setting Mail Redirection with PowerShell

with No Comments

Recently we came across a scenario where we were using MigrationWiz to perform a migration from a hosted Exchange platform to an on-prem Exchange 2013 deployment. We’d use Migration Manager for AD to migrate the user accounts already, but since we weren’t using the Exchange portion of that particular tool, we had to go through and create the mailboxes on Exchange 2013, and set mail redirection during the time we were syncing mail from the hosted Exchange platform. Also, the customer had asked that we evenly spread out the mailboxes over all the 12 databases they had on 2013.

To do this, we used the below PowerShell one-liners with a CSV file to import. 

Note: This should work in Exchange 2010 and 2016, but we haven’t tested it there yet. As always, test before running anything in production.

First, you’ll need a single CSV with this format

User1,SMTP:[email protected],DB01
User2,SMTP:[email protected],DB02
User3,SMTP:[email protected],DB03
User4,SMTP:[email protected],DB04
User5,SMTP:[email protected],DB05

Save the CSV to a location you can reach it from Exchange Management Shell on the environment you want to create the mailboxes and set redirection in. Then launch Exchange Management Shell, and execute the below PowerShell cmdlets, substituting the correct path to the CSV.

Create the mailboxes

Import-CSV c:\temp\mailboxes.csv | foreach { Enable-Mailbox -Identity $_.sAMAccountName -Database $_.Database }

Set mail redirection by populating the targetAddress attribute

Import-Csv c:\temp\mailboxes.csv | foreach { Set-ADuser -Identity $_.sAMAccountName -add @{targetAddress = $_.targetAddress} }

If you run into any issues, don’t hesitate to reach out to us!

Leave a Reply