# Create New user file from imported CSV

**URL:** <https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827>\
**Category:** PowerShell Help\
**Created:** [March 7, 2023, 11:19am UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827 "2023-03-07T11:19:07Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hunicrem](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@hunicrem](https://forums.powershell.org/u/hunicrem)\
**Post date:** [March 7, 2023, 11:19am UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/1 "2023-03-07T11:19:07Z")

</div>

Hi,

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:

[/code]  
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 = “@domain.com”  
$Emailaddr = $Fname + “.” + $LName + $EmailDomain  
$EmailLogin = $samAccountName + $EmailDomain

write-host $Emailaddr

}  
[/code]

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,  
Hunicrem

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 7, 2023, 12:03pm UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/2 "2023-03-07T12:03:18Z")

</div>

hubert,  
Welcome back to the forum. 👋🏽 Long time no see

> [@hunicrem](#):
>
> the variable values are not taking

Where do you know? 🤔

Try this snippet:

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

$Result

```

---

<div class="post-metadata">

**Author:** ![hunicrem](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@hunicrem](https://forums.powershell.org/u/hunicrem)\
**Post date:** [March 7, 2023, 12:21pm UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/3 "2023-03-07T12:21:04Z")

</div>

Thanks for your reply Olaf.

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

> Blockquote  
> sAMAccountName :  
> FName :  
> LName :  
> Passwd :  
> Emailaddr : [.@domain.com](mailto:.@domain.com)  
> UPN : @domain.com

This is what the csv looks like:

> Blockquote  
> |First Name|LastName|Username|Password|  
> |Jeff|doe|a99999|!IMFksd9!f|

So I still have no clue why the variables stay empty

greetz

---

<div class="post-metadata">

**Author:** ![Olaf](https://sea1.discourse-cdn.com/flex019/user_avatar/forums.powershell.org/olaf/32/992_2.png) [@Olaf](https://forums.powershell.org/u/Olaf)\
**Post date:** [March 7, 2023, 12:28pm UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/4 "2023-03-07T12:28:26Z")

</div>

> [@hunicrem](#):
>
> This is what the csv looks like:

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

---

<div class="post-metadata">

**Author:** ![hunicrem](https://avatars.discourse-cdn.com/v4/letter/h/a88e4f/32.png) [@hunicrem](https://forums.powershell.org/u/hunicrem)\
**Post date:** [March 7, 2023, 12:35pm UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/5 "2023-03-07T12:35:56Z")

</div>

> [@Olaf](#):
>
> '|

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 🙂  
greetz

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex019/uploads/powershell/original/1X/385e4f9fe133561ad30a814262fe0e0ae6bc3ef0.png) [@system](https://forums.powershell.org/u/system)\
**Post date:** [February 10, 2024, 5:34pm UTC](https://forums.powershell.org/t/create-new-user-file-from-imported-csv/21827/6 "2024-02-10T17:34:04Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
