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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

MASEE Solution Guide - Technical Dept HeadCommented:
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

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

MaheshArchitectCommented:
Why are you importing users instead of migrating ?

Unable to understand the requirement..
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why.

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
MaheshArchitectCommented:
replace "foreach" with % or Foreach-Object and try
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

MASEE Solution Guide - Technical Dept HeadCommented:
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

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.
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.
MASEE Solution Guide - Technical Dept HeadCommented:
Glad to know it helped and thanks for being on board.
Appreciate if you a comment as answer and close the question

MAS
IT on The DotConsultantAuthor Commented:
The  script works great thanks for all your help I really appreciate it
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.