user3082478
user3082478

Reputation: 51

How can I convert a csv file to lowercase or uppercase maintaining it's structure using powershell?

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

Answers (2)

Joe
Joe

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

mjolinor
mjolinor

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

Related Questions