Skip to main content

Bulk Import Contacts into Exchange Online in Office 365 Using PowerShell

Author by Michael Epping

Exchange Online in Office 365 conveniently provides a graphical interface so administrators can perform basic tasks like create mailboxes, add SMTP addresses, create Distribution Groups, and create Contacts.  However, the management portal doesn't allow administrators to perform actions in bulk in many cases, which is one of the reasons Microsoft allows PowerShell access to Exchange Online.  I've noticed in the Office 365 forums that a lot of administrators want a simple way to import hundreds or thousands of contacts, which will appear in the Global Address List.  Luckily, this is a very simple task that can be accomplished with PowerShell and a CSV file. The first step is to configure your CSV file in a format that PowerShell can use when connected to Exchange Online.  Microsoft provides a handy sample CSV file, which you can download here http://community.office365.com/en-us/forums/183/t/10030.aspx.  The file from Microsoft is actually a .txt file, but you can open that file in Excel and fill in the information under the appropriate headers.  Don't worry if you don't have information for each column as any missing cells will just be skipped.  I would recommend deleting the Manager column though, as that is the one column that causes problems if the cells are blank.  A filled out CSV will look like this, although with real user information: 2013-03-26 12_50_09 Save your file as a CSV somewhere on your computer.  Make sure you change the file type to .csv because it won't work if you leave it as a .txt file. The next step is to start a remote PowerShell session connected to Exchange Online.  If you need help doing this please follow my guide here http://www.concurrency.com/blog/create-a-shortcut-to-remote-powershell-for-office-365-and-exchange-online/.  I just saved my CSV to my Downloads folder, so the commands will reflect that.  Change any paths in the following commands to reference the location your CSV file is saved:

  • cd C:UsersmichaelDownloads
  • Import-Csv .ExternalContacts.csv | %{New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}
  • $ContactInfo = Import-Csv .ExternalContacts.csv
  • $ContactInfo | foreach {Set-Contact $_.Name -StreetAddress $_.StreetAddress -City $_.City -StateOrProvince $_.StateorProvince -PostalCode $_.PostalCode -Phone $_.Phone -MobilePhone $_.MobilePhone -Pager $_.Pager -HomePhone $_.HomePhone -Company $_.Company -Title $_.Title -OtherTelephone $_.OtherTelephone -Department $_.Department -Fax $_.Fax -Initials $_.Initials -Notes $_.Notes -Office $_.Office}

After running that command your contacts will have all their information populated from the spreadsheet.  You can verify if it was successful by choosing a contact and running this command:

  • Get-Contact DarrenParker | fl

If successful the output will resemble this: 2013-03-26 13_11_43 Similarly, in the Exchange Control Panel in the Office 365 portal you can see that new contact objects are visible: 2013-03-26 13_12_13 Hopefully these commands can simplify the otherwise tedious process of importing contacts into Exchange Online.

Author

Michael Epping

Systems Engineer