Share via


New mail contact using powershell

Question

Monday, October 17, 2016 1:25 PM

Hi,

i am using following power-shell script to create bulk mail contacts.

Import-Csv “C:\test.csv” | ForEach {New-MailContact -Name $_.Name -Firstname $_.FirstName -LastName $_.LastName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit “Mail Contacts”}

i want to add "Job title", "Department" and "Company" in the script. Can anybody help me. What should i need to add in the current script.

All replies (4)

Monday, October 17, 2016 6:39 PM ✅Answered

Those parameters are not available as input for New-MailContact, you have to set them post creation. Simply add another line in your script that runs the Set-Contact cmdlets (yes, Set-Contact as opposed to Set-MailContact):

Set-Contact $_.ExternalEmailAddress -Department $_.department -Title $_.title -Company $_.company

Tuesday, October 18, 2016 8:19 AM ✅Answered

Thank you Vasil

One more thing how can i add "telephone Number" in the set-contact in the script.

Hi,

Here are the parameters that you can use for Set-Contact and Set-MailContact cmdlet.

https://technet.microsoft.com/en-us/library/bb124535(v=exchg.160).aspx

https://technet.microsoft.com/en-us/library/aa995950(v=exchg.160).aspx

Save the above the command in .ps1 file, then run this script file in EMS.

Import-Csv “C:\test.csv” | ForEach {New-MailContact -Name $_.Name -Firstname $_.FirstName -LastName $_.LastName -ExternalEmailAddress $_.ExternalEmailAddress -OrganizationalUnit “contoso.com/Users”
Set-Contact $_.ExternalEmailAddress -Department $_.department -Title $_.title -Company $_.company -Phone $_.Phone}

Regards,

Lynn-Li

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have feedback for TechNet Subscriber Support, contact [email protected].


Tuesday, October 18, 2016 6:22 AM

Thank you Vasil

One more thing how can i add "telephone Number" in the set-contact in the script.


Tuesday, October 18, 2016 7:36 AM

Simply use one of these parameters:

HomePhone
MobilePhone
OtherHomePhone
OtherTelephone
Phone