Fun with PowerShell – character manipulation…

I was investigating a localization test failure today and ran into the following error message:


‘actual error is 爠捡湩敤氠捥整牵꿿渠攧楸瑳畯渠攧瑳瀠獡甠獳敩⹲਍, expected ‘


Since it was failing in the French locale, getting what appeared to be a Chinese error message didn’t make a lot of sense. A coworker confirmed that it was garbage. My next guess was that it was actually an ANSI string that was mangled into Unicode. In other words, two characters in the source string became one character in the output. But how to test this? Well – fortunately we have PowerShell! I pasted the string into the console window which looked like:


$t = ‘??????????????????????????????????’


And then used casts to take the string apart:


&{$ofs=”; [string][char[]] ([int[]] [char[]] $t |% { $_ -band 0xff ;  [int] ($_ / 256 ) })}


Running this exercise in stunt-casting translated $t back into:


La racine de lecteur rÿF:\ÿ° n’existe pas ou n’est pas un dossier.


Now that’s more like the error message one would expect in the French locale J


Anyone want to take a stab at explaining how this works?




Bruce Payette [MSFT]
Windows PowerShell Tech Lead

Visit the Windows PowerShell ScriptCenter at: