Convert Upper case to Lower Case on CSV content through PowerShell

%3CLINGO-SUB%20id%3D%22lingo-sub-467245%22%20slang%3D%22en-US%22%3EConvert%20Upper%20case%20to%20Lower%20Case%20on%20CSV%20content%20through%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-467245%22%20slang%3D%22en-US%22%3E%3CP%3EHello%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EI%26nbsp%3B%20tried%20following%20PowerShell%20script%20and%20it%20work%20well%20but%20some%20how%20it%20convert%20whole%20string%20from%20Upper%20to%20lower.%20i%20need%20to%20keep%20first%20letter%20of%20string%20as%20upper%20%2C%20do%20not%20want%20to%20cover%20as%20lower%20for%20first%20letter.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24a%20%3D%20%22E%3A%5CUser%5CStaff%5Ccims%22%3CBR%20%2F%3E%24b%20%3D%20(get-content%20%22%24a%5Cstaff.csv%22%20-raw)%3CBR%20%2F%3E((%22%24b%22).ToLower()).trim(%22%20%22)%20-split%20(%22%2C%2C%22)%20%7C%3CBR%20%2F%3EOut-File%20-FilePath%20E%3A%5CUser%5CStaff%5Ccims%5Cstaff1.csv%20-Encoding%20UTF8%20%7C%3CBR%20%2F%3EGet-Process%20%7C%20Out-Host%20-Paging%7C%20Format-Table%20-wrap%20-Property%20Emp%2CLastFirst%2CLast%2CFirst%2Cemail.title%2Clocation%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-467245%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3Elower%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EPowerShell%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3Eupper%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-470007%22%20slang%3D%22en-US%22%3ERe%3A%20Convert%20Upper%20case%20to%20Lower%20Case%20on%20CSV%20content%20through%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-470007%22%20slang%3D%22en-US%22%3E%3CP%3ESomething%20like%20this%20should%20do%20it%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%3E(%24b%5B0%5D%20%2B%20%24b.Substring(1).ToLower()).Trim(%22%20%22)%20-split%20...%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-471534%22%20slang%3D%22en-US%22%3ERe%3A%20Convert%20Upper%20case%20to%20Lower%20Case%20on%20CSV%20content%20through%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-471534%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThank%20you!%3C%2FP%3E%3CP%3EIt%20is%20still%20returning%20all%20lower%20case%20instead%20of%20first%20letter%20capital%20and%20reset%20are%20lower%20case.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-471555%22%20slang%3D%22en-US%22%3ERe%3A%20Convert%20Upper%20case%20to%20Lower%20Case%20on%20CSV%20content%20through%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-471555%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F58%22%20target%3D%22_blank%22%3E%40Vasil%20Michev%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EFixed%20through%20following%20script%2C%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%24TextInfo%20%3D%20(Get-Culture).textinfo%3CBR%20%2F%3E%24TextInfo.ToTitleCase(%24b%5B0%5D%20%2B%20%24b.Substring(1).ToLower()).Trim(%22%20%22)%20-split(%22%2C%2C%22)%20%7C%3CBR%20%2F%3E%3CBR%20%2F%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-472408%22%20slang%3D%22en-US%22%3ERe%3A%20Convert%20Upper%20case%20to%20Lower%20Case%20on%20CSV%20content%20through%20PowerShell%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-472408%22%20slang%3D%22en-US%22%3E%3CP%3EWell%20it's%20more%20fun%20if%20you%20get%20just%20the%20building%20blocks%20and%20do%20the%20complete%20solution%20yourself%20%3Ap%3C%2Fimg%3E%20Or%20in%20other%20words%20I%20was%20being%20lazy%20and%20didn't%20want%20to%20copy%2Fpaste%20the%20entire%20script%20sample.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Occasional Contributor

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
Highlighted

Something like this should do it:

 

($b[0] + $b.Substring(1).ToLower()).Trim(" ") -split ...
Highlighted

@Vasil Michev 

 

Thank you!

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

Highlighted

@Vasil Michev 

 

Fixed through following script,

 

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

Highlighted

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.