-1

I have a database of user information but I want to set the first character of column called firstName into a capital letter. I tried doing a for-each loop calling the column name in the script to covert it using the Get-Culture class, but my method is not working, how can I accomplish this conversion?

$UserList = Import-Csv C:\Users\Administrator\Desktop\salesdbs.csv 

$UserList | Select-Object -First 100 | Format-Table -AutoSize


$UserList =  foreach ($firstName in $UserList) { 

$UserList = (Get-Culture).TextInfo.ToTitleCase($UserList) 

}

Echo "$UserList"
Katz
  • 826
  • 3
  • 19
  • 40

2 Answers2

2

Try this:

$UserList = Import-Csv C:\Users\Administrator\Desktop\salesdbs.csv

foreach ($row in $UserList) {
    $row.firstName = (Get-Culture).TextInfo.ToTitleCase($row.firstName)
}
obe
  • 7,378
  • 5
  • 31
  • 40
1

I can't determine the structure (schema) of your CSV file from the OP. I'm guessing that each rows has multiple columns, with one of the columns called FirstName. If that's not correct please update OP with schema of your CSV file.

Try this:

$UserList = Import-Csv C:\Users\Administrator\Desktop\salesdbs.csv 
$UserList | Select-Object -First 100 | Format-Table -AutoSize

for ($ndx = 0; $ndx -lt 100; $ndx++) { 
  $userlist[$ndx].firstname = (Get-Culture).TextInfo.ToTitleCase($userlist[$ndx].firstname) 
}
Echo "$UserList"
Frode F.
  • 52,376
  • 9
  • 98
  • 114
Χpẘ
  • 3,403
  • 1
  • 13
  • 22