Link to home
Start Free TrialLog in
Avatar of Leonardo Storelli
Leonardo Storelli

asked on

iMPORT-CSV ERROR

Hi

i'm trying to import new mail contact from .csv file,  by this command in exchange 2010 powershell

Import-Csv  c:\name.csv | foreach  {new-mailcontact  -name  $_.name  -externalemailaddress  $_.emailaddress;set-contact  –Alias $_.alias  -identity  $_.name  -office  $_.office  -department  $_.department}

but the system returns the following error:

[PS] C:\>Import-Csv  c:\name.csv | foreach  {new-mailcontact  -name  $_.name  -externalemailaddress  $_.emailaddress;set
-contact  -Alias $_.alias  -identity  $_.name  -office  $_.office  -department  $_.department}
The term 'Import-Csv ' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
 spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:12
+ Import-Csv  <<<<  c:\name.csv | foreach  {new-mailcontact  -name  $_.name  -externalemailaddress  $_.emailaddress;set
-contact  -Alias $_.alias  -identity  $_.name  -office  $_.office  -department  $_.department}
    + CategoryInfo          : ObjectNotFound: (Import-Csv :String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Any IDEA?

thanks
Avatar of oBdA
oBdA

My guess is you didn't actually type the line, but copied and pasted it from somewhere else, either a website or some word processor (as opposed to a text editor). These have a tendency to replace the real minus "-" (ASCII 45) with a pretty hyphen (like ASCII 150 or 151).
Paste the line into the console again, but before you hit Enter, edit the line and delete and retype each and every "-".
create a CSV file in the below format. This does not have department and office
name           emailaddress                    alias      
Mike Witts     Mike.Witts@n.com     mike.witts  
John Smith    John.Smith@n.com     john.witts  


and  try this command and post the result
 
Import-Csv c:\name.csv | foreach {new-mailcontact  -name  $_.name  -externalemailaddress  $_.emailaddress –Alias $_.alias}

Open in new window


Try with couple of users first
Avatar of Leonardo Storelli

ASKER

Hi

I created the CSV file in this format:

COLUMN A
----------------------------------------------------------------------------------------------------------------------------------------------
1 Name, emailaddress, Alias, office, department
2 Stephen King, stephen @ king.com, stephenking, press, IT

the result of command

[PS] C:\>new-mailcontact  -name  "Chris Ashton"  -externalemailaddress   "Chris@tailspintoys.com" ;set-contact  -Alias "ashton" -office  "press"  -department  "IT"
Name                      Alias                                          RecipientType
----                      -----                                          -------------
Chris Ashton              ChrisAshton                                    MailContact
A positional parameter cannot be found that accepts argument 'ashton'.
    + CategoryInfo          : InvalidArgument: (:) [Set-Contact], ParameterBindingException
    + FullyQualifiedErrorId : PositionalParameterNotFound,Set-Contact
SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial