Forum Discussion

Sagar Patel's avatar
Sagar Patel
Copper Contributor
Apr 17, 2019

Convert Upper case to Lower Case on CSV content through PowerShell

Hello,

 

I  tried following PowerShell script and it work well but some how it convert whole string from Upper to lower. i need to keep first letter of string as upper , do not want to cover as lower for first letter.

 

$a = "E:\User\Staff\cims"
$b = (get-content "$a\staff.csv" -raw)
(("$b").ToLower()).trim(" ") -split (",,") |
Out-File -FilePath E:\User\Staff\cims\staff1.csv -Encoding UTF8 |
Get-Process | Out-Host -Paging| Format-Table -wrap -Property Emp,LastFirst,Last,First,email.title,location

 

Thank you

4 Replies

  • Something like this should do it:

     

    ($b[0] + $b.Substring(1).ToLower()).Trim(" ") -split ...
    • Sagar Patel's avatar
      Sagar Patel
      Copper Contributor

      VasilMichev 

       

      Fixed through following script,

       

      $TextInfo = (Get-Culture).textinfo
      $TextInfo.ToTitleCase($b[0] + $b.Substring(1).ToLower()).Trim(" ") -split(",,") |

      • VasilMichev's avatar
        VasilMichev
        MVP

        Well it's more fun if you get just the building blocks and do the complete solution yourself :P Or in other words I was being lazy and didn't want to copy/paste the entire script sample.

    • Sagar Patel's avatar
      Sagar Patel
      Copper Contributor

      VasilMichev 

       

      Thank you!

      It is still returning all lower case instead of first letter capital and reset are lower case.

Resources