Create New user file from imported CSV


I’m really new to Powershell and trying to understand the syntax.

So i have a CSV-file, that contains new users in the format ‘First Name;LastName,Username,Password’, headers are mentioned in the CSV.

I’m trying to write a script, that will concatenate some of the fields and create a new CSV file, populated with those concatenations.
The goal is to create an email address for login and email.

This is what I have so far:

Import-Module ActiveDirectory
$CSVImport = Import-CSV c:\output\C2303~00086.csv
ForEach ($NewUser in $CSVImport)
$samAccountName = $NewUser.Username
$FName = $NewUser.“First Name”
$LName = $NewUser.LastName
$Passwd = $NewUser.Password
$EmailDomain = “
$Emailaddr = $Fname + “.” + $LName + $EmailDomain
$EmailLogin = $samAccountName + $EmailDomain

write-host $Emailaddr


From what I understand, my concatenation is correct, however, the variable values are not taking, not sure why. What is wrong in this syntax?

Thanks in advance,

Welcome back to the forum. :wave:t4: Long time no see

Where do you know? :thinking:

Try this snippet:

$CSVImport = Import-CSV c:\output\C2303~00086.csv
$Result = 
ForEach ($NewUser in $CSVImport) {
        sAMAccountName = $NewUser.Username
        FName          = $NewUser.'First Name'
        LName          = $NewUser.LastName
        Passwd         = $NewUser.Password
        Emailaddr      = '{0}.{1}' -f $NewUser.'First Name', $NewUser.LastName
        UPN            = '{0}' -f $NewUser.Username


Thanks for your reply Olaf.

Unfortunately, I see the same thing, values stay empty:

sAMAccountName :
FName :
LName :
Passwd :
Emailaddr :

This is what the csv looks like:

|First Name|LastName|Username|Password|

So I still have no clue why the variables stay empty


If your CSV really uses pipe symbols as delimiter you have to change your Import-Csv command and add -Delimter '|'.

Thanks Olaf. That didn’t work. Our system uses ; as a delimiter, but this csv file is coming from somewhere else. I saved the file as a new CSV file, added delimiter ; and voila, variables are correctly being populated!

I think I can go on from here… Thanks a lot, and if I have another question, I know where to go :slight_smile: