combine username with domain is returning length

$file= Import-Csv D:\files\users.csv
ForEach ( $user in $file)
{
$i= $user.User + ‘@’ + $user.Domain
$i | Export-Csv D:\files\users1.csv -NoTypeInformation -Append
}

I am trying to combine username with domain name from a csv file. However when I just output the variable it displays the information fine. However when I export to csv it displays the length in the csv file. Any suggestions on what is wrong here?

 

its how export-csv creates object values and their properties. You can change from export-csv to

out-file with -append and that’ll work.

@techsavy83

There are many ways,to achieve these type of task but as per your code, you can use out-file instead of Export-CSV

Example:

$file= Import-Csv D:\files\users.csv
ForEach ( $user in $file)
{
    $i= $($user.User)+'@'+$($user.Domain)
    $i | out-file D:\files\user1.csv -Append
}

Thanks, that works. However any idea why Export-csv is outputting the length instead of the information?

Here’s a link with the same problem:

https://stackoverflow.com/questions/19450616/export-csv-exports-length-but-not-name

 

The accepted answer explains why.

Thanks for the reply. My doubt is cleared now.