I made a script that generates usernames based on names out of a CSV. Now I want to export those usernames to the same CSV I got them, but in a third column that's named username. How do I merge the output and export them to my CSV? Can I capture the output of Write-Host? I just noticed that my Nachname.substring doesn't include the first letter, why is that?
$users = Import-Csv -Path C:\Users\username\Desktop\Namen.csv -Header "Vorname","Nachname","Username" -Delimiter ';'
Foreach($user in $users) {
$number = Get-Random -Minimum 10 -Maximum 99
$firstName = $user.Vorname.Substring(0,1)
$lastName = $user.Nachname.Substring(0.7)
$usernames = Write-Host "$($firstName)$($lastName)$($number)"
}
My CSV looks like this:
Monika Aldegar MAldegar57
Iban Ashok IAshok81
Aelmaer Dusko ADukso15
and so on...
now those are two columns for the first name and last name. I want the created username in the third column