Power Shell Script to create Contact-Cards imported from a .csv

Posted: March 21, 2017 in Microsoft Exchange

Good Day to All, I was asked to create Contact Cards in Microsoft Exchange 2010, now this seems like an easy task in the EMC (Exchange Management Console) but when you have 2,000 contacts to create, EMC doesn’t seem much fun after all. Scripting power! I went to Microsoft Website and got some information on how to do it.

Contact-Card.csv

Contact-Card-csv

 

“New-MailContact -ExternalEmailAddress -Name [-Alias ] [-ArbitrationMailbox ] [-Confirm []] [-DisplayName ] [-DomainController ] [-ExternalDirectoryObjectId ] [-FirstName ] [-Initials ] [-LastName ] [-MacAttachmentFormat ] [-MessageBodyFormat ] [-MessageFormat ] [-ModeratedBy ] [-ModerationEnabled <$true | $false>] [-Organization ] [-OrganizationalUnit ] [-OverrideRecipientQuotas ] [-PrimarySmtpAddress ] [-SendModerationNotifications ] [-UsePreferMessageFormat <$true | $false>] [-WhatIf []]”

after a little fine tuning it ended up like this: “Import-CSV Contact-Card.csv | ForEach-Object {New-MailContact -Name $_.Name -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit $_.OrganizationalUnit -WhatIf}

Let’s break it down:

  1. Import-CSV Contact-Card.csv (where contact-card.csv is the file where we have the information we want to import.
  2. | ForEach-Object {                        (Since we’re doing batch it’s going to execute the command for each record)
  3. New-MailContact                          (Power Shell command to create a mail contact)
  4. -Name $_.Name                            (Exchange Field and Colum name match on csv)
  5. -ExternalEmailAddress $_.ExternalEmailAddress         (Exchange Filed and Column name match on csv)
  6. -OrganizationalUnit $_.OrganizationalUnit               (Exchange Filed and column name match on csv)

-WhatIf

Now the “-WhatIf” at the end of the command will show us a preview of the outcome, once were are ready to execute the command in Production, remove the -WhatIF

After a while, all 2000 contact cards were created…. Next o the Agenda… Script to Forward emails to the created contact cards…

 

 

 

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