Replacing Special Chars like “Umlauts”

by Aug 31, 2016

PowerShell 2+

Sometimes it becomes necessary to replace special characters like German “Umlauts” in order to normalize user names or email addresses.

Here is a little function that illustrates how this can be done:

#requires -Version 3


function Convert-Umlaut
{
  param
  (
    [Parameter(Mandatory)]
    $Text
  )
    
  $output = $Text.Replace('ö','oe').Replace('ä','ae').Replace('ü','ue').Replace('ß','ss').Replace('Ö','Oe').Replace('Ü','Ue').Replace('Ä','Ae')
  $isCapitalLetter = $Text -ceq $Text.toUpper()
  if ($isCapitalLetter) 
  { 
    $output = $output.toUpper() 
  }
  $output
}

To convert a string, use it like this:

 
PS C:\> Convert-Umlaut -Text "Mößler, Christiansön" 
Moessler, Christiansoen 
 

Twitter This Tip! ReTweet this Tip!