Add Contacts to Office 365 in Bulk with PowerShell

I had a project recently where we were migrating from hosted Exchange to Office 365. We implemented AAD Connect to sync Active Directory (AD) user objects for the user mailboxes that where being migrated. However, we manually created shared and resource mailboxes, groups, and contacts in O365 as those were not going to be created in AD for synchronization.

For this article, we will add contacts to Office 365 in bulk with PowerShell using a CSV file.

The command we will use for this task is New-MailContact. Since New-MailContact only requires the Name and ExternalEmailAddress parameters, we will create our CSV file similar to the following (MyO365Contacts.csv) which I saved in the C:\Scripts directory.

Add Contacts 2

 

Now that we have our CSV file set, we need to connect to Office 365 with PowerShell.

Once connected to the O365 tenant, we will run the following script (Create-MyO365Contacts.ps1) to add the list of contacts from the CSV file…

Import-Csv "C:\Scripts\MyO365Contacts.csv" | foreach-object { New-MailContact -Name $_.MyName -ExternalEmailAddress $_.MyPrimaryEmail }

 

While processing the script, each contact is confirmed when added successfully.

Add Contacts 3

 

Finally, we confirm the contacts have been added successfully by checking the O365 admin and Exchange admin centers.

Add Contacts 4

 

Add Contacts 5

 

Reference(s):

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s