Reputation: 51
I have a CSV file that with contents that needs to be converted to all lowercase
I have tried the code below but it doesn't maintain the CSV structure.
(Get-Content C:\_Scratch\export.csv).ToLower() | Out-File C:\_scratch\export.csv
$Init = Import-Csv C:\_Scratch\export.csv
Is there another option I can try?
Upvotes: 1
Views: 8219
Reputation: 11
$TempContentArray = $NULL
$TempContent = $NULL
$TempContent = Get-Content C:\_Scratch\import.csv
Foreach ($Line in $TempContent)
{
$TempContentArray += $Line.ToUpper()
}
$TempContentArray | C:\_scratch\export.csv
$Init = Import-Csv C:\_Scratch\export.csv
Upvotes: 0
Reputation: 68331
Get-Content
is going to give you string array. Add the -Raw
switch to read it in as a single string, and the .toupper()
and .tolower()
string methods should work on that.
(Get-Content C:\_Scratch\export.csv -Raw).ToLower() | Out-File C:\_scratch\export.csv
Upvotes: 4