PowerShell: Converting first character of a string to uppercase

The below converts the first character of $givenname and $sn variables to uppercase. This is useful if you are receiving information from an external form and need to convert them to a useable format.

 



$givenname = Read-Host "First Name:"


$sn = Read-Host "Last Name:"




#Converts first letter of First/Lastname to uppercase


$givenname = $givenname.substring(0,1).toupper()+$givenname.substring(1).tolower()


$sn = $sn.substring(0,1).toupper()+$sn.substring(1).tolower()

0 thoughts on “PowerShell: Converting first character of a string to uppercase”

Leave a Reply

Your email address will not be published. Required fields are marked *