Link to home
Create AccountLog in
Avatar of annayeg
annayeg

asked on

powershell script to create new-mailcontact

I have the following basic script to create mailcontact from a csv file.  However, when I run it I get the following error message:
new-mailcontact: cannot bind argumet to paramet 'name' because it is null.

$csv = Import-Csv 'C:\Contacts1.csv'
foreach ($line in $csv)
{
New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit “contacts” -Alias $_.Alias

}

My contacts1.csv contains 1 line of name, emailaddress, alias.
ASKER CERTIFIED SOLUTION
Avatar of KenMcF
KenMcF
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
You could also try this

Import-Csv 'C:\Contacts1.csv' | %{
New-MailContact -Name $_.DisplayName -ExternalEmailAddress $_.EmailAddress -OrganizationalUnit “contacts” -Alias $_.Alias

}
Avatar of Aard Vark
Also verify that each of the CSV columns have values and one of the lines does not have a blank for the display name field.

IE:

displayname,emailaddress,alias
user1,user1@blah,user1
,user2@blah,user2
user3,user3@blah,user3