1

I am working on a new script in Powershell and I would like to ask if someone know of a method or function to replace all "Non-English" letter in a string to English letters. The reason for this is due to the New-ADUser function where AD only accepts English letters for SamAccountName and UserPrincipalName.

Example of a string would be

$Name= "TRẦN NGÔ ỬNG HẠNH"

There will be names with all kinds of Non-English letters both Asia, Europe, etc hence its would not be sufficient with simple If-Then Replace.

if ($Name= -like "*Ầ*")
{
$Name = $Name.replace('Ầ','A')
}
Chris
  • 33
  • 5
  • May I suggest that instead of automatically handling it you do a regexp to check if its a-z A-Z 0-9 instead and hand it back to the person putting in the input. Since there are almost unlimited characters that is non latin and many of them is not possible to translate to english. Hence better to have the user fix the problem with a proper errormessage. – Daniel Björk Jul 27 '20 at 08:22
  • and one other sidenote, e.g. Scandinavian letters like ÅÄÖ translates to two characters. Å = AA, Ä = AE, Ö = OE – Daniel Björk Jul 27 '20 at 08:24
  • Hi, This is integration between our HR system and AD. The vendor for the HR system tells that there is no way they will translate all users to English letters. Before we used .replace but in that case, it was only for Norwegian users with ØÆÅ so that was an easy task. I can send it back as you suggest but that will result in more employees are sent back for correction than users created. I was hoping for a function for this and if not I guess I will have to tell them the facts and they will need to translate to English. – Chris Jul 27 '20 at 08:35
  • See if [previous question](https://stackoverflow.com/q/7836670/503046) works for you. And just as @DanielBjörk points out, be wary of name collisions. Transliteration rules are complex and highly culture dependent. Also, see a list of common false assumptions about [people's names](https://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/). – vonPryz Jul 27 '20 at 08:36

1 Answers1

1

Hi Daniel Björk and vonPryz,

Thanks, both for you replies, I found a solution I will go by from the link suggested. I have also read the article about people's names, and for this case, users will still be able to use their original name as a display name but since Microsoft made it hard to use other than "English" characters in AD we will need to convert their names.

Solution (This will work on the Asian names tested so far) For Scandinavian we will still have to add a .replace.

function Remove-Diacritics {
param ([String]$src = [String]::Empty)
  $normalized = $src.Normalize( [Text.NormalizationForm]::FormD )
  ($normalized -replace '\p{M}', '')
}

$Name = Remove-Diacritics ("TRẦN NGÔ ỬNG HẠNH")


If ($Name -match "[a-z]"){
Write-host "$Name - OK"
}Else{
Write-host "$Name - Send back"
}
Chris
  • 33
  • 5