We help IT Professionals succeed at work.

exchange 2010 newcontact command

changari
changari asked
on
I recently had the task to create a few hundred email contacts for exchange 2010 server. I then ran into a problem that made me scratch my head for little while. I had a user that was sending emails and the recipients were receiving winmail.dat files instead of the attachments that was actually sent with email. After some deductive reasoning I cam to realize that it was the contact that I made. The were all set to  USE MAPI rich text format.. which was causing the issue. I went back to my command to create the contacts and added the parameter -UsePreferMessageFormat ($false) which should translate to "Never" but it doesn't seem to work. I tried several ways to do it and every time it comes up <not set> which translates to Use default Settings........Does anyone have a way to get this actually work. Am I missing something?
Comment
Watch Question

Will SzymkowskiSenior Solution Architect
Most Valuable Expert 2015
Top Expert 2015

Commented:
You are using the wrong switch for this. You need to use UseMapiRichTextFormat Never.

Set-MailContact -Identity -UseMapiRichTextFormat Never

Open in new window


Will.

Author

Commented:
hi...

  that -UseMapiRichTextFormat Never is for the command Set-MailContact  
  I am using new-mailcontact ..  here is the command that I am using:

Import-Csv “d:\new7.csv” | ForEach {New-MailContact
-Name  ($_."LastName"+”, “+$_."FirstName"+” “+$_."MD" )      
-Alias ($_."LastName"+$_."FirstName")  
-Firstname $_.FirstName -LastName $_.LastName
-ExternalEmailAddress $_.ExternalEmailAddress
-OrganizationalUnit “xxxx.com/contacts” -UsePreferMessageFormat ($false)}

this reads my csv file and creates all the contact without a problem.. the only issue is that USE MAPI rich text format is defaulted and the  -UsePreferMessageFormat ($false) doesn't seem to work.. do I need to use another option or command with my command??
Senior Solution Architect
Most Valuable Expert 2015
Top Expert 2015
Commented:
All you need you do at the end of your script is add the | set-mailcontact -UseMapiRichTextFormat Never. Set-MailContact accepts pipeline in put so just add it at the end of your script.

Import-Csv “d:\new7.csv” | ForEach {New-MailContact 
 -Name  ($_."LastName"+”, “+$_."FirstName"+” “+$_."MD" )       
 -Alias ($_."LastName"+$_."FirstName")  
 -Firstname $_.FirstName -LastName $_.LastName 
 -ExternalEmailAddress $_.ExternalEmailAddress 
-OrganizationalUnit “xxxx.com/contacts” | set-mailcontact -UseMapiRichTextFormat Never}

Open in new window


If that does not work (which it should) try putting your Import-csv command in a variable and then use the ForEach command.

Will.

Author

Commented:
Will,

   that was the ticket.. could you tell me if I had needed to use one of the variables from the new-contact command.. like -alias or -name from new-mailcontact for the set-mailcontact  -identity .. what i put.. luckily it uses the contact that i just created by default.
Will SzymkowskiSenior Solution Architect
Most Valuable Expert 2015
Top Expert 2015

Commented:
When you use the "|" command it will use the user in the pipeline for the second command which is why then you use the Set-MailContact you do not need to use the "-Identity" switch.

The other way i was mentioning in my previous post is the following...
$MailContacts = Import-Csv “d:\new7.csv”
ForEach ($MailContact in $MailContacts)  {New-MailContact 
 -Name  ($_."LastName"+”, “+$_."FirstName"+” “+$_."MD" )       
 -Alias ($_."LastName"+$_."FirstName")  
 -Firstname $_.FirstName -LastName $_.LastName 
 -ExternalEmailAddress $_.ExternalEmailAddress 
-OrganizationalUnit “xxxx.com/contacts” | set-mailcontact -UseMapiRichTextFormat Never}

Open in new window


If you first script worked which it should have then you do not need to use a variable like i have illustrated.

Will.

Author

Commented:
Thank you........................