Quick tip: Handling non-ASCII characters in Internet domain names

The character set allowed in the Domain Names System is based on ASCII, but ICANN have later approved the Internationalized domain name (IDNA) system. It was proposed in 1996 and first implemented in 1998, and lets you use characters outside the ASCII-only scheme (Unicode).

You might have seen these names before; they look like this: xn--bcher-kva.com

So how would you handle these names with PowerShell? Luckily for us, the .NET framework got us covered, in the form of the System.Globalization.IdnMapping class.

Let’s try it out:

$idnMapping = New-Object -TypeName 'System.Globalization.IdnMapping'
$idnMapping.GetAscii('bücher.com')

The above code should output ‘xn--bcher-kva.com’.

Let’s try it the other way:

$idnMapping.GetUnicode('xn--bcher-kva.com')

This time the output should be ‘bücher.com’.

You can read more about this class at MSDN.

Leave a comment