• Home
  • Topics
    • Office 365
    • Teams
    • SharePoint Online
    • Exchange 2019
    • Exchange 2016
    • Exchange 2013
    • Hybrid
    • Certificates
    • PowerShell
    • Migration
    • Security
    • Azure
  • Blog
  • Podcast
  • Webinars
  • Books
  • About
  • Videos
    • Interview Videos
    • How To Guide Videos
  • Subscribe
    • Facebook
    • Twitter
    • RSS
    • YouTube

Practical 365

You are here: Home / Exchange Server / PowerShell Script to Import Mail Contacts from a CSV File to Exchange

PowerShell Script to Import Mail Contacts from a CSV File to Exchange

November 23, 2016 by Paul Cunningham 9 Comments

Import-MailContactsFromCSV.ps1 is a PowerShell script to automate the creation of Exchange mail contacts using a CSV file for input.

The current version of the script supports a CSV file containing the following fields, which are the minimum details required for creating a mail contact in Exchange:

  • Name
  • ExternalEmailAddress

The script looks for a file named Contacts.csv by default, or you can use the optional -CSVFileName parameter to specify your own file name. You can also set a default OU for contacts in the script, or use the -OU parameter to specify an OU.

Download the script from the TechNet Gallery or GitHub.

Example usage:

1
2
3
4
5
C:ScriptsImportContacts>.Import-MailContactsFromCSV.ps1
 
C:ScriptsImportContacts>.Import-MailContactsFromCSV.ps1 -CSVFileName externalcontractors.csv
 
C:ScriptsImportContacts>.Import-MailContactsFromCSV.ps1 -OU "exchangeserverpro.net/Company/Contacts"


If you are providing this script to a non-administrator to use, you can configure an RBAC custom role to limit their permissions to only allow them to create contacts in a specific OU, as demonstrated here.

Exchange Server Contacts, Exchange, PowerShell, Scripts

Comments

  1. Miguel B. says

    April 7, 2020 at 12:07 am

    This was extremely helpful after a migration to Google, where contacts needed to be created for all users in the new google domain to enable forwarding.

    Thanks a lot!! Saved me possibly a few hours or coding / testing something similar.

    Reply
  2. Alejandrina says

    September 18, 2019 at 8:57 pm

    This blog was… how do you say it? Relevant!! Finally I’ve found something which helped me.
    Thank you!
    cheap essay editing service cheap essay editing service

    Reply
  3. Pedro Maria says

    August 31, 2019 at 12:36 am

    The term ‘Import-MailContactsFromCSV.ps1’ is not recognized as the name of a cmdlet, function, script file, or operable

    Reply
    • Andrew Tozzi says

      September 5, 2019 at 11:57 pm

      Make sure you dot source the script, if you’re in the correct directory, you still need to preface the filename with “./”. Powershell will do this for you if you use the tab completion feature by typing some of the filename and then the tab key, e.g. “Update-MailCo” .

      Reply
  4. cheryl says

    May 15, 2019 at 4:46 am

    I tried code:

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

    I get this error:

    The external e-mail address joseph.smith@verizonwireless.com is not an SMTP e-mail address.
    + CategoryInfo : NotSpecified: (NAMPR18A001.PRO….com/Joe Smith:ADObjectId) [New-MailContact], Recipien
    tTaskException
    + FullyQualifiedErrorId : [Server=DM5PR1801MB1995,RequestId=ffea9430-096d-4d70-a70b-5b08387a160b,TimeStamp=5/14/20
    19 6:32:22 PM] [FailureCategory=Cmdlet-RecipientTaskException] 5870EC2D,Microsoft.Exchange.Management.RecipientTas
    ks.NewMailContact
    + PSComputerName : outlook.office365.com

    what does it mean it is not an SMTP email address?
    very novice on powershell… just trying to upload our csv file of contacts into exchange admin users…
    thank you

    Reply
    • Matt Dodd says

      February 20, 2020 at 10:21 pm

      Make sure there is no blank space after the email address preceding the 1st comma in each record.
      I had the same error that I didn’t see when opening the CSV file in excel but it was evident when using notepad. Once this space was removed it worked.

      Reply
  5. Alessandro Tinivelli says

    September 12, 2018 at 1:03 am

    @Paul: you have forgotten to write exactly how the .csv should be written.
    I had to reverse engineer your code in order to understand that.

    the file should be like this

    Name,ExternalEmailAddress
    john,john@example.com

    Reply
  6. CaZzzle says

    August 15, 2018 at 11:23 pm

    I keep getting an OU related error.

    Command I use:
    Import-MailContactsFromCSV.ps1 -CSVF
    ileName C:\IT\importimport.csv -OU “domain.org/MyBusiness/Users/TargetOU”
    The OU domain.org/MyBusiness/Users/TargetOU was not found
    At C:\Users\me\Downloads\Import-MailContactsFromCSV-V1.00\Import-MailContactsFromCSV.ps1:64 char:5
    + throw $message
    + ~~~~~~~~~~~~~~
    + CategoryInfo : OperationStopped: (The OU …e was not found:String) [], RuntimeException
    + FullyQualifiedErrorId : The OU domain.org/MyBusiness/Users/TargetOU was not found

    Reply
    • Alessandro Tinivelli says

      September 12, 2018 at 12:59 am

      @CaZzzle you must run the script in the Exchange Powershell

      Reply

Leave a Reply Cancel reply

You have to agree to the comment policy.

Recent Articles

  • Microsoft Launches Group Ownership Governance Policy
  • Making the Case for Identity Governance in Azure Active Directory
  • Prepare an Office 365 migration plan assessment using PowerShell
  • Microsoft Releases May 2022 Exchange Server Security Updates
  • New Future of Work for Microsoft 365, IOT and more: Practical 365 Podcast S3 Ep. 2

Copyright © 2022 Quadrotech Solutions AG · Disclosure · Privacy Policy
Alpenstrasse 15, 6304 Zug, Switzerland