Bulk Import Contacts to Office 365 Global Address List

You may have noticed that the Office 365 portal doesn’t offer you a way to easily import a list of contacts into your company’s Global Address List (GAL). In order to bulk import contacts, you would need to use PowerShell. Here are instructions on how to use PowerShell.

Gathering Contacts

1. Download this External Contacts CSV and open it up in a program like Excel.

2. Delete the sample data.

3. Collect your contact data and fill out the columns. You must provide an email address for each contact. If any of your contacts do not have an email address, do not add them to this list because they cannot be imported. It’s recommended that you fill out these columns for each contact.

  • ExternalEmailAddress
  • Name
  • FirstName
  • LastName

4. The other columns are optional. If any column is left blank, it will not be imported into the GAL.

Set up PowerShell 3.0

If you haven’t used PowerShell before, we will first need to configure your computer to use PowerShell with Office 365. If you have Windows 8, Windows 8.1, or Windows server 2012, you can start on step 3.

1. Install Microsoft .NET Framework 4.0 or Microsoft .NET Framework 4.5. You don’t need to install both.

2. Install Windows Management Framework 3.0.

3. Click on the Start icon on your desktop and search for “PowerShell”.

4. Right click on “Windows PowerShell” and select “Run as administrator”.

5. In the PowerShell window, type this command

Set-ExecutionPolicy RemoteSigned

6. When asked if you want to change the execution policy, type “Y” and then press the “Enter” key.

Powershell1

For more detailed information, click here.

Import Contacts with PowerShell

1. Click on the Start icon on your desktop and search for “PowerShell” and click on it to open PowerShell.

2. Type in this command and enter in your Office 365 Global Admin credentials.

$Cred = Get-Credential

3. Type in this line to create your remote session to Office 365.

$Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $Cred -Authentication Basic –AllowRedirection

4. Type in this line to start the session.

Import-PSSession $Session

5. If you do not get any errors running the above lines, you are finally connected to Office 365 with PowerShell. We can now start importing the contacts.

6. Rename the CSV file to something simpler like “ExternalContacts.csv” and place the file in C:\.

7. Type in this command to create the contacts with basic information.

Import-Csv C:\ExternalContacts.csv|%{New-MailContact -Name $_.Name -DisplayName $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}

8. Now that the contacts have been created, we will run these two commands to fill in the rest of the information.

$Contacts = Import-CSV C:\ExternalContacts.csv

$contacts | 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 -Manager $_.Manager}

 

18 Comments on “Bulk Import Contacts to Office 365 Global Address List

  1. I get the following error message :
    —————————————————————————————————————————————
    Cannot bind argument to parameter ‘Name’ because it is an empty string.
    + CategoryInfo : InvalidData: (:) [New-MailContact], ParameterBindingValidationE
    xception
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorEmptyStringNotAllowed,New-MailC
    ontact
    + PSComputerName : pod51036psh.outlook.com

    —————————————————————————————————————————————

    Any ideas ?

    1. Hi Thomas,

      The message “Cannot bind argument to parameter ‘Name’ because it is an empty string” indicates that the “Name” field in the CSV file is blank. You’ll need to put something there, then try to run the import script again.

  2. Hi,

    thank you for the instructions.

    I have error with the last commnad to fill the rest information:
    Couldn’t find a user or contact with identity “-“.

    Could you explain which column is Identity or where I should look to solve the error?
    I am not familiar with powershell so I will be very grateful for any help.

    Adam

    1. this is the full error message

      Couldn’t find a user or contact with identity “-“.
      + CategoryInfo : NotSpecified: (:) [Set-Contact], ManagementObjectNotFoundException
      + FullyQualifiedErrorId : [Server=AM3PR06MB1172,RequestId=6dbbaf58-307f-4883-a5ba-8e1e75dcc894,
      TimeStamp=02/10/2015 10:47:50] [FailureCategory=Cmdlet-ManagementObjectNotFoundException] 803A4
      03,Microsoft.Exchange.Management.RecipientTasks.SetContact
      + PSComputerName : ps.outlook.com

      1. Hi Adam,

        Do you happen to have any fields in the column for “Name” filed with “-“? The command in step 7 first imports all of the contacts into the list with basic information like email address and name. Step 8 then goes down the list, finds the contact with the “Name” column that already exists and then modifies the contact with the other fields (phone, company, address, etc.).

        How about trying this command with a slight modification? Instead of using the “Name” column, it’ll find the contact with the “ExternalEmailAddress” column.

        $contacts | ForEach {Set-Contact -Identity $_.ExternalEmailAddress -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 -Manager $_.Manager}

  3. I got to different errors when I tried t resolve the first error is below, second under that;

    Cannot process argument transformation on parameter ‘Manager’. Cannot convert va
    iguration.Tasks.UserContactIdParameter”. Error: “Parameter values of type Micros
    ntactIdParameter can’t be empty. Specify a value, and try again.
    Parameter name: identity”
    + CategoryInfo : InvalidData: (:) [Set-Contact], ParameterBindin…
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Contact

    2nd error:
    Cannot process argument transformation on parameter ‘Manager’. Cannot convert va
    iguration.Tasks.UserContactIdParameter”. Error: “Parameter values of type Micros
    ntactIdParameter can’t be empty. Specify a value, and try again.
    Parameter name: identity”
    + CategoryInfo : InvalidData: (:) [Set-Contact], ParameterBindin…
    + FullyQualifiedErrorId : ParameterArgumentTransformationError,Set-Contact

    any ideas???

    Thanks

    1. Hi Daniel,

      I posted this in a previous reply. Can you try this instead? Also, the error message you’ve posted is not complete. Some of the words have been cut off. I will need the full error message to understand what it’s telling me.

      How about trying this command with a slight modification? Instead of using the “Name” column, it’ll find the contact with the “ExternalEmailAddress” column.

      $contacts | ForEach {Set-Contact -Identity $_.ExternalEmailAddress -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 -Manager $_.Manager}

  4. Hi,

    Thank you for your wonderful and precise instructions.

    I am getting ready to take the plunge with contacts.

    I assembled all contacts from all users into the CSV but users being users have utilized all sorts of characters in the Name, FirstName, LastName and Company fields.

    Before I get many error messages, is there a general guideline of what special characters not to use in those fields?

    Atm I see many -,&,(,),/,., etc

    I see from previous comments that ‘-‘ is not allowed. how about the others?

    Thanks

    Yiannis

    1. Hi Yiannis,

      Some fields will have restrictions while others will not. Avoid using special characters for the column “Name” and “ExternalEmailAddress”. There should be no issues with you using special characters for the other fields. The “-” character is allowed only when it is surrounded on both sides by other characters. From the earlier comment, the person only had the contacts’ name listed as “-“, which is not allowed. Here is a more comprehensive list: https://support.microsoft.com/en-us/kb/2439357

      From the script, the field “Name” is actually applied to 2 fields in Office 365: “Name” or (“Alias”) and “DisplayName”. The “Name”/”Alias” field is the one column that has restricted characters. We can theoretically add a new column to the CSV for “DisplayName”, which will have no restriction on characters, and modify the import script to:

      Import-Csv C:ExternalContacts.csv|%{New-MailContact -Name $_.Name -DisplayName $_.DisplayName -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}

  5. Hi,

    I did the import successfully.

    Just a few things that I noticed that might help others.

    If there is an empty column, like ‘Manager’ it will cause the 2nd part of the import to fail and no fields will be populated. I removed the completely empty columns from the csv and amended the script accordingly.

    The Name field has a max character allowance of 64.

    The Initials field has a max character allowance of 6.

    No trailing or leading whitespaces are allowed in any field. Sometimes they creep-in the data if it was exported from a local address book. I used the TRIM command in Excel to remove them prior to csv creation.

    Exporting Excel data to a proper csv is not a staightforward process. I had to use a macro to achieve the proper format.

    All-in-all a very educational process.

    Thanks again for all your help.

    Yiannis

  6. I put 43 contacts with email, name (first and last) firstname and lastname in my csv. I used the sample and just left the other columns blank for each name.

    Everytime i try to import the file, it says

    Import-csv : The member “xxxxx” is already present.

    In the file there was 2 mike, so I made one of them Mike2. So I ran again, and It moves on to another name.

    Chris

    1. Hi Chris,

      Thanks for pointing that out! I just replied to one of the other comments with a modified script on how to handle duplicates.

  7. Hi,
    I am getting error on step 7 while importing csv. Error displayed below.

    Active Directory operation failed on DB4PR02A002DC03.EURPR02A002.prod.outlook.com. The object ‘CN=N/A,OU=aisle5.onmicrosoft.com,OU=Microsoft Exchange Hosted Organizations,DC=EURPR02A002,DC=prod,DC=outlook,DC=com’ already exists.
    + CategoryInfo : NotSpecified: (:) [New-MailContact], ADObjectAlreadyExistsException
    + FullyQualifiedErrorId : [Server=HE1PR0201MB1500,RequestId=ee8f4101-f22c-4566-a9c7-8930daad2330,TimeStamp=6/5/201
    6 7:04:03 AM] [FailureCategory=Cmdlet-ADObjectAlreadyExistsException] 258159D,Microsoft.Exchange.Management.RecipientTasks.NewMailContact

    Can you please suggest.

    Thanks

    Aqeel.

    1. Hi Aqeel,

      This error indicates that there is a duplicate contact with the same name in the “Name” column. Easiest way to deal with this is to modify the “Name” of the duplicate and try the import again.

      Other way to handle this is to modify the data and script. In the script, the field “Name” is actually applied to 2 fields in Office 365: “Name” or (“Alias”) and “DisplayName”. The “Name”/”Alias” field is the one column that must be unique. You can add a new column to the CSV for “DisplayName”. and modify the import script to:

      Import-Csv C:ExternalContacts.csv|%{New-MailContact -Name $_.Name -DisplayName $_.DisplayName -ExternalEmailAddress $_.ExternalEmailAddress -FirstName $_.FirstName -LastName $_.LastName}

      “DisplayName” is what you see when you look at the contact. The “Name” column is now the unique identifier for the contact. For example:

      ExternalEmailAddress, DisplayName, Name, FirstName, LastName
      darrenp@fabrikam.com, Darren Parker, Darren Parker1, Darren, Parker
      darrenp@fabrikam.com, Darren Parker, Darren Parker2, Darren, Parker
      tanjap@contoso.com, Tanja Plate, Tanja Plate, Tanja, Plate
      allieb@tailspintoys.com, Allie Bellew, Allie Bellew, Allie, Bellew

  8. I’m soooo glad I found this, and soooo glad it worked pretty much first time. To undo the access rights I granted my PC do I run Set-ExecutionPolicy RemoteSigned again and choose the SUSPEND option? Or how? Am I leaving any access open? i.e Please could you explain how to shut down the access?

Leave a Reply

Your email address will not be published. Required fields are marked *