CSV bulk Email creation

My company recently merged with another one, both of us are on Exchange 2010, I currently have this task, I have to import all the users from their exchange Server to our exchange Server so I can create an autoforward since we are in two different domains,  I been trying to use a bulk CSV import with PS but my script keeps giving me string errors

Import-CSV "C:\Scripts\Users123.csv"
ForEach-Object { New-Mailbox -Lastname $_.”LastName” -FirstName $_.”FirstName” -Name $_."Name" -Organization "Mycompany.local" -Database "Local" -UserPrincipalName $_.”UserPrincipalName” -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}

Open in new window


And this is the error I get
ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
At line:1 char:214
+ ForEach-Object { New-Mailbox -Lastname $_.LastName -Name $_.Name -FirstName $_.FirstName -Organization EnhancedVision
.local -Database Local -UserPrincipalName $_.UserPrincipalName -Password (ConvertTo-SecureString <<<<  $_.password -AsP
lainText -Force)}
    + CategoryInfo          : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSe
   cureStringCommand

Open in new window


Any thoughts ?

Thanks in Advance
IT on The DotConsultantAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MAS (MVE)EE Solution GuideCommented:
Hi IT on The Dot,
Welcome to Experts Exchange.
Create a CSV file as below and try the below command.
Capture.JPG
$Password=Read-Host “Enter Password” –AsSecureString

Import-CSV CreateMailboxes.csv | ForEach {New-Mailbox -Alias $_.alias -Name $_.name FirstName $_.”FName” -Lastname $_.”LName” -userPrincipalName $_.UPN -Database “Mailbox Database name” -OrganizationalUnit Users -Password $Password}

Open in new window

0
IT on The DotConsultantAuthor Commented:
Hello MAS EE MVE,

Thank you for the help, I created the CSV file following your method and ran the script and I got this in return

Missing opening '(' after keyword 'foreach'.
At line:1 char:9
+ ForEach  <<<< {New-Mailbox -Alias $_.alias -Name $_.name FirstName $_."FName" -Lastname $_."LName" -userPrincipalName
 $_.UPN -Database "EnhancedVision" -OrganizationalUnit Users -Password $Password}
    + CategoryInfo          : ParserError: (OpenParenToken:TokenId) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingOpenParenthesisAfterKeyword

Open in new window

0
MaheshArchitectCommented:
Why are you importing users instead of migrating ?

Unable to understand the requirement..
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

IT on The DotConsultantAuthor Commented:
Our companies merged but we are keeping separate brands, but we need to communicate in between are we are to receive emails on both domains , so when someone sends and email to one of the new executives at  user1@ourcompany.com can be automatically forward it to user1@newcompany.org via autoforward, so I'm importing user names from the  new company to my exchange to create those rules, so I'm researching bulk import and/or creation because there are over 80 employees that will need this method, our companies are in both ends of U.S. one in Cali and the other one in Florida

Thanks
0
MaheshArchitectCommented:
replace "foreach" with % or Foreach-Object and try
0
random0Commented:
From the original post it seems you don't have pipeline "|" between import-csv and foreach...


Import-CSV "C:\Scripts\Users123.csv" |
ForEach-Object { New-Mailbox -Lastname $_.”LastName” -FirstName $_.”FirstName” -Name $_."Name" -Organization "Mycompany.local" -Database "Local" -UserPrincipalName $_.”UserPrincipalName” -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}

Open in new window

0
MAS (MVE)EE Solution GuideCommented:
I tested and it worked in my lab.
Capture2.JPGCSV format
 Capture.JPGCommand
Import-Csv C:\cert\Users.csv | foreach {New-Mailbox -Alias $_.alias -Name $_.name -FirstName $_.Firstname -LastName $_.Lastname -UserPrincipalName $_.UPN -Database "Mailbox Database 0716284986" -OrganizationalUnit Users -Password (ConvertTo-SecureString $_.password -AsPlainText -Force)}

Open in new window


Thanks
MAS
1

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
random0Commented:
Yes, i believe the whole problem is caused by the missing pipeline, from the beginning and following your post it was still missing although you have it in your code block.
0
IT on The DotConsultantAuthor Commented:
@MAS EE MVE

Thanks I changed the CSV to reflect the Password and made some changes  to UPN and it works.

Thank you all for the help.
0
MAS (MVE)EE Solution GuideCommented:
Glad to know it helped and thanks for being on board.
Appreciate if you a comment as answer and close the question

MAS
0
IT on The DotConsultantAuthor Commented:
The  script works great thanks for all your help I really appreciate it
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Powershell

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.