Bulk import of mail contacts

Soldato
Joined
5 Jul 2003
Posts
16,206
Location
Atlanta, USA
Hi,
Can anyone tell me whats going wrong here? Im using this cmdlet to try and import some mail contacts in Exchange Powershell
Import-CSV C:\ch.csv | ForEach-Object {New-MailContact -Name ($_."First Name"+" "+$_."Last Name") -DisplayName ($_."First Name"+" "+$_."Last Name") -FirstName $_."First Name" -LastName $_."Last Name" -OrganizationalUnit $_."Organizational Unit" -ExternalEmailAddress $_."EmailAddress" }

But it errors every time on the 6th contact in! :(

Invoke-Command : Cannot bind parameter 'Name' to the target. Exception setting "Name": "The property value is invalid.
The value can't contain leading or trailing whitespace."
At USER FOLDER PATH
1.contoso.com.psm1:27888 char:29
+ $scriptCmd = { & <<<< $script:InvokeCommand `
+ CategoryInfo : WriteError: ( : ) [New-MailContact], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.Exchange.Management.RecipientTasks.NewMailContact

Any ideas?
 
Last edited:
Yes.
Ive modified the code to this:
[PS] C:\>Import-CSV C:\ch.csv | ForEach-Object {New-MailContact -Name $_.Name -FirstName $_.First Name -LastName $_.Last
Name -OrganizationalUnit $_.Organizational Unit -ExternalEmailAddress $_.EmailAddress }

And now it errors with this:
A positional parameter cannot be found that accepts argument 'Name'.
+ CategoryInfo : InvalidArgument: (:) [New-MailContact], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,New-MailContact
 
Back
Top Bottom