locked
Creating Mail Contacts with Power Shell RRS feed

  • Question

  • I've began receiving a monthly CSV file that is a dump of the GAL from another company we own. They are totally autonomous and there is no chance of any AD integration between the two organizations, so these records are being imported into our AD as mail contacts. 

    Here is the powershell script I created to do this: 

    $ContactList = Import-Csv c:\import.csv 
    foreach($contact in $ContactList) 

            $name=$contact.displayName + " - EX" 
            New-MailContact -Name $name -ExternalEmailAddress $contact.mail -DisplayName $name -Firstname $contact.givenName -Initials $contact.initials -Lastname $contact.sn -OrganizationalUnit "EXContacts" 



    This seems to work well enough, just tested and it creates the contacts. However, some of the fields in the source CSV file (in particular, title, company, etc) don't seem to exist in the New- MailContact function. Am I missing something, or is there a way to add these at creation, or after the fact via another commandlet? 

    Any help is appreciated. 

    Thursday, March 15, 2012 5:31 PM

Answers

  • The set-mailcontact parameters only allow you to set mail enabled attributes for AD attributes such as title and company you need to use the set-contact cmdlet.

    James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com

    • Marked as answer by DavBurTul Friday, March 16, 2012 8:12 PM
    Thursday, March 15, 2012 5:42 PM

All replies

  • The set-mailcontact parameters only allow you to set mail enabled attributes for AD attributes such as title and company you need to use the set-contact cmdlet.

    James Chong MCITP | EA | EMA; MCSE | M+, S+ Security+, Project+, ITIL msexchangetips.blogspot.com

    • Marked as answer by DavBurTul Friday, March 16, 2012 8:12 PM
    Thursday, March 15, 2012 5:42 PM
  • Thanks, that worked perfect. Appreciate the help!
    Friday, March 16, 2012 8:13 PM
  • Final script if it helps anyone else out:

    # Import Contacts
    # By David
    # 3/14/2012
    $ContactList = Import-Csv c:\import.csv
    foreach($contact in $ContactList) 
    { 
    	$name=$contact.displayName + " - EX"
    	$alias=$contact.givenName + $contact.initials + $contact.sn + "EX"
    	$alias = $alias.Replace(" ", "")  # get rid of any spaces since they aren't allowed in alias
    	$alias = $alias.Replace(",", "")  # get rid of any commas since they aren't allowed in alias
    	$alias = $alias.Replace("(", "")  # get rid of any parens since they aren't allowed in alias
    	$alias = $alias.Replace(")", "")  # get rid of any parens since they aren't allowed in alias
    	New-MailContact -Name $name -alias $alias -ExternalEmailAddress $contact.mail -DisplayName $name -Firstname $contact.givenName -Initials $contact.initials -Lastname $contact.sn -OrganizationalUnit "EXContacts"
    	set-contact -identity $alias -title $contact.title -notes $contact.description -phone $contact.telephoneNumber -department $contact.department -company $contact.company -office $contact.physicalDeliveryOfficeName
    }

    Friday, March 16, 2012 8:15 PM