Search code examples
powershellcsvuppercaselowercase

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?


Solution

  • 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