PowerShell – Convert strings to lower- or upper case

Every once in a while you may find yourself in a situation where you would like to convert a string (bunch of characters) to lower- or upper case characters… for example when creating Virtual Machines.

When you’re working with strings, it is possible to convert those characters with the “toLower()” method… like so:
image

But what if you want to convert lower characters to upper characters? Use the “toUpper()” method as shown below:
image

4 comments

  1. Walid2mi says:

    hi

    just for fun:

    $phrase = “THIS IS MY TEXT RIGHT NOW”

    -join $($phrase.ToCharArray()|%{
     if([char]::IsLower($_)) {$_}else{[char]::ToLower($_)}})

  2. Walid2mi says:

    or this:

    $phrase = “THIS IS MY TEXT RIGHT NOW”

    $phrase -replace ‘(w)’,”$([char]::ToLower($1))”

  3. Jeff Wouters says:

    Hi Walid2mi,
    The “-Join” oneliner you’ve provided does work, but it’s a lot more code… yet still, it’s a different approach and fun to see that there’s another way to accomplish the same 🙂
    However, the “-replace” twoliner doesn’t work…

  4. Brian Smyth says:

    “UPPERCASE TEST”.tolower()

Leave a Reply

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