Exchange Import Contacts from CSV and Add / Modify information

Stefanos Constantinou 61 Reputation points
2021-01-03T16:35:55.577+00:00

Hello everyone,

I have about 5000 contacts to add in the Global Address List in the Exchange Server and I need to use the Exchange Management shell and use a CSV.

Of what I have noticed, I cannot define all CSV fields in the New-MailContact so they all are added so I need to just create the contacts and then add/modify the rest of the values.

I have the following Code:

Import-Csv C:\Stefanos\MyCSV.csv | %{New-MailContact -Name $_.Alias -FirstName $_.FirstName -LastName $_.LastName -Alias $_.Alias -ExternalEmailAddress $_.Email -OrganizationalUnit $_.OUpath}

the above successfully creates the contact but after that, I need to modify some contact information like change DisplayName, add MobilePhone, Phone (BusinessPhone), JobTitle etc

$ContactInfo = Import-Csv C:\Stefanos\DummyCSMCYGAL4CSMITA.csv
$contacts | ForEach {Set-Contact $_.Name -DisplayName $_.DisplayName -Phone $_.Phone -MobilePhone $_.MobilePhone -Pager $_.Pager -HomePhone $_.HomePhone -Company $_.Company -Title $_.Title -OtherTelephone $_.OtherTelephone -Department $_.Department}

the above command on the other hand, shows an error:

Cannot bind argument to parameter 'Identity' because it is null.

  • CategoryInfo : InvalidData: (:) [Set-Contact], ParameterBindingValidationException
  • FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Set-Contact
  • PSComputerName : servername.domain

I tried to add Identity or define it in my CSV but it seems I cannot get it right

Does someone have a recommendation or how I can fix the problem?

Exchange | Exchange Server | Management
{count} votes

Accepted answer
  1. Andy David - MVP 157.4K Reputation points MVP Volunteer Moderator
    2021-01-03T16:43:20.4+00:00

    Well, first you set the csv to $contactinfo
    $ContactInfo = Import-Csv C:\Stefanos\DummyCSMCYGAL4CSMITA.csv

    then you have it set to:

    $contacts

    The Identity parameter specifies the contact that you want to modify. You can use any value that uniquely identifies the contact. Use that in your csv instead..
    For example:

    Set-contact -Identity <Name> etc etc...  
    

    Name
    Distinguished name (DN)
    Canonical DN
    GUID
    https://learn.microsoft.com/en-us/powershell/module/exchange/set-contact?view=exchange-ps

    Or use set-mailcontact

    https://learn.microsoft.com/en-us/powershell/module/exchange/set-mailcontact?view=exchange-ps


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.