none
wsman encoding issue- unicode is not supported RRS feed

  • Question

  • We want to execute a PowerShell script on remote machine to collect data. For this we are using WSMAN protocol. We are making a wsman-soap request with required PowerShell script and sending this to hyperv machine using http. There script is executed and data is sent back to us using wsman, but currently we have found that it is not supporting unicode chars. So because of this non-English chars are garbled at receiving end, we are currently not able to resolve this issue. We have checked this for Hyperv German and Hyperv Japanese system.

    I am thinking this as command line problem. As you can see we are adding command shell in soap request and same is executed on hyperv machine, after execution we are getting data in base64 format, when we are decoding received data using Base64.decode, data should come in UTF-8 format, but unfortunately for non-English char garbled data is shown.

    Sample soap request :

    <?xml version='1.0' encoding='UTF-8'?>               

    <s:Envelope xmlns:s='http://www.w3.org/2003/05/soap-envelope'  xmlns:a='http://schemas.xmlsoap.org/ws/2004/08/addressing'  xmlns:w='http://schemas.dmtf.org/wbem/wsman/1/wsman.xsd'> 

    <s:Header>   <a:To>http://155.35.128.64:5985/wsman</a:To>   <w:ResourceURI s:mustUnderstand='true'>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/cmd</w:ResourceURI>    

    <a:ReplyTo>      

    <a:Address s:mustUnderstand='true'>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>    

    </a:ReplyTo>    

    <a:Action s:mustUnderstand='true'>http://schemas.microsoft.com/wbem/wsman/1/windows/shell/Command</a:Action>        

    <w:MaxEnvelopeSize s:mustUnderstand='true'>153600</w:MaxEnvelopeSize>        

    <a:MessageID>uuid:b62d857a-b8ca-4795-b795-d84a3099ce0b</a:MessageID>       

    <w:ContentEncoding> UTF-8 </w:ContentEncoding>         

    <w:Locale xml:lang='en-US' s:mustUnderstand='false'></w:Locale>

    <w:SelectorSet xmlns:w="http ://schemas.dmtf.org/wbem/wsman/1/wsman.xsd">

    <w:Selector Name="ShellId">9FA05544-FC36-454C-8AD1-6E1F41999F98</w:Selector>

    </w:SelectorSet>

    <w:OptionSet>

    <w:Option Name='WINRS_CONSOLEMODE_STDIN'>TRUE</w:Option>

    </w:OptionSet>

    <w:OperationTimeout>PT60.000S</w:OperationTimeout>    

    </s:Header>    

    <s:Body><CommandLine xmlns='http://schemas.microsoft.com/wbem/wsman/1/windows/shell'>

    <Command><![CDATA[echo function main > %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^{ >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$XenDesktopUser ^= "" >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo gWmi ^-ComputerName 155.35.128.64 ^-NameSpace root\virtualization\V2  ^-query "Select * from Msvm_ComputerSystem" ^| Out^-File c:\1.txt ^-encoding 'utf8' >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$LoadPercentages ^= Get^-Content c:\1.txt ^-encoding 'utf8' >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$LoadPercentages >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^} >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo main >> %TEMP%\ScriptFile-0.3611362671107353.ps1 & Powershell "%TEMP%\ScriptFile-0.3611362671107353.ps1" & Del "%TEMP%\ScriptFile-0.3611362671107353.ps1"]]>

    </Command>

    </CommandLine></s:Body>  

    </s:Envelope>

    Please let me know if you required other information from my side.

    Wednesday, April 29, 2015 10:17 AM

All replies

  • Hello Abhishek,

    Thank you for your question. A member of the protocol documentation team will respond to you soon.

    Best regards,
    Matt Weber | Microsoft Open Specifications Team

    Wednesday, April 29, 2015 6:10 PM
  • Hello Abhishek - I'm researching this for you.

    Is it possible for you to share steps to reproduce this behavior between windows to windows English OS ? I assume, in order to reproduce this issue we need non-English OS, Is this assumption correct ?

    Thanks


    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

    Wednesday, April 29, 2015 6:31 PM
  • Hi Tarun,

    Yes one of our remote hyperv machine is in non english OS (Japanese/German).

    I am making batch script and adding that batch script in wsman soap request. (Check below mentioned soap request part)This batch script will create the temporary powershell script on hyperv machine. And then powershell script will execuete a powershell query which produces the ouput in unicode format (Like Caption,Description in Msvm_ComputerSystem is in unicode) and the same output is received using wsman command id. What i have found is wsman output is not coming in proper UTF-8 fomat. Non-english chars are garbled while transfering query output from hyperv machine to request machine(Where program is running).

    <Command><![CDATA[echo function main > %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^{ >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$XenDesktopUser ^= "" >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo gWmi ^-ComputerName 155.35.128.64 ^-NameSpace root\virtualization\V2  ^-query "Select * from Msvm_ComputerSystem" ^| Out^-File c:\1.txt ^-encoding 'utf8' >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$LoadPercentages ^= Get^-Content c:\1.txt ^-encoding 'utf8' >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^$LoadPercentages >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo ^} >> %TEMP%\ScriptFile-0.3611362671107353.ps1&echo main >> %TEMP%\ScriptFile-0.3611362671107353.ps1 & Powershell "%TEMP%\ScriptFile-0.3611362671107353.ps1" & Del "%TEMP%\ScriptFile-0.3611362671107353.ps1"]]>

    </Command>

    If you required i can share the sample java program with you to produce the scenario.

    Thursday, April 30, 2015 9:50 AM
  • Hello Anhishek -

    Can you please drop me mail at - dochelp at Microsoft dot com and share the java program ?

    Thanks.


    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

    Thursday, April 30, 2015 5:41 PM
  • Hi Tarun,

    I have dropped a mail to dochelp at Microsoft dot com with java test program, Please let me know if you still have any query.

    thanks,

    Friday, May 1, 2015 1:49 PM
  • Hello Abhishek - Thanks for the mail. Let us work through dochelp and later update this post with the resolution.

    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

    Friday, May 1, 2015 6:15 PM
  • Per analysis. the issue was with the codepage set on command prompt on remote server. WINRM gets data from command prompt and since the code page is set incorrectly, WINRM layer receives incorrect data.

    Following command resolved the issue on remote server command prompt -

    chcp 65001 - Which will change the code page to UTF-8. Also, you need to use Lucida console fonts.
    type 1.txt

    The guidance was to execute command on remote machine to set the code page before executing the command so that proper formatted data is fed to WINRM layer.

    Tarun Chopra | Escalation Engineer | Open Specifications Support Team

    Tuesday, January 5, 2016 10:08 PM