Because of the coding problem, Java is called by Remote Call WinRM form, in the console return character, including Chinese, display ... , there are garbled Chinese.
By adjusting the $outputencoding way, still appear garbled. So in the way of the curve implementation, the result of executing the script is obtained by redirecting the result to the file (the specified file encoding format) and then reading the file form.
The code is as follows:
Package com.test;
Import java.io.UnsupportedEncodingException;
Import java.util.ArrayList;
Import Java.util.HashMap;
Import java.util.List;
Import Java.util.Map;
Import Io.cloudsoft.winrm4j.client.WinRmClientContext;
Import Io.cloudsoft.winrm4j.winrm.WinRmTool;
Import Io.cloudsoft.winrm4j.winrm.WinRmToolResponse; public class Remotewinrm4jtest {public static void main (string[] args) throws Unsupportedencodingexception, Interrup
tedexception {Winrmclientcontext context = winrmclientcontext.newinstance ();
Winrmtool.builder Builder = WinRmTool.Builder.builder ("192.168.1.128", "Administrator", "password");
Builder.setauthenticationscheme (AUTHSCHEMES.NTLM);
Builder.port (5985);
Builder.usehttps (FALSE);
Builder.disablecertificatechecks (FALSE);
Builder.context (context);
Winrmtool tool = Builder.build ();
Tool.setoperationtimeout (0L);
System.out.println ("========"); Winrmtoolresponse Resp = tool.executeps ("C:/users/administrator/windowsauditpolicy.ps1 |out-file windowsauditpolicy_result.txt-encoding
UTF8 ");
Thread.Sleep (3000);
RESP = Tool.executecommand ("type C:\\users\\administrator\\windowsauditpolicy_result.txt");
String out = Resp.getstdout ();
String err = Resp.getstderr ();
System.out.println (out);
Context.shutdown (); }
}