I have a .csv file that contains usernames in the first column. They are in the form of FirstName LastName. I want to take the FirstName and add the first character of the LastName onto it, and delete the space. I then want to add @someemailaddress.com.
Here is the example:
This is what I have:
DisplayName, OtherColumn
Sam Jones, otherdata
Paul Jones, otherdata
This is what I want:
DisplayName, OtherColumn
[email protected], otherdata
[email protected], otherdata
Ideas?
By using Import-Csv, Select-Object, and Export-Csv, you can set up a pipeline that gets the contents of the CSV file, selects a new calculated DisplayName property with an expression that performs your string manipulations, and exports the data back out as CSV.
Import-Csv data.csv | Select-Object @{
Name = "DisplayName"
Expression = {
$parts = $_.DisplayName.Split();
$parts[0] + $parts[1][0] +"@someemailaddress.com"
}
}, OtherColumn | Export-Csv data-new.csv
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With