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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s