Package org.metricshub.winrm.command
Class WinRMCommandExecutor
java.lang.Object
org.metricshub.winrm.command.WinRMCommandExecutor
-
Method Summary
Modifier and TypeMethodDescriptionstatic WindowsRemoteCommandResultexecute(String command, WinRMHttpProtocolEnum protocol, String hostname, Integer port, String username, char[] password, String workingDirectory, long timeout, List<String> localFileToCopyList, Path ticketCache, List<AuthenticationEnum> authentications) Execute a command on a remote Windows system and return an object with the output of the command.
-
Method Details
-
execute
public static WindowsRemoteCommandResult execute(String command, WinRMHttpProtocolEnum protocol, String hostname, Integer port, String username, char[] password, String workingDirectory, long timeout, List<String> localFileToCopyList, Path ticketCache, List<AuthenticationEnum> authentications) throws IOException, TimeoutException, WindowsRemoteException Execute a command on a remote Windows system and return an object with the output of the command. You can specify local files to be copied to the remote system before executing the command. If the command contains references to these local files, it will be updated to reference the path on the remote system where the files have been copied. Example:WinRemoteCommandExecutor.execute( "CSCRIPT c:\\MyScript.vbs", null, "remote-srv", null, null, null, 30000, Arrays.asList("c:\\MyScript.vbs"), false);This will copy c:\\MyScript.vbs to remote-srv, typically in C:\\Windows\\Temp\\winrm-upload-MYHOST and the command that is executed will therefore become:CSCRIPT "C:\\Windows\\Temp\\winrm-upload-MYHOST\\MyScript.vbs"- Parameters:
command- The command to execute. (Mandatory)protocol- The HTTP protocol (HTTP by default)hostname- Host to connect to. (Mandatory)port- The port (5985 for HTPP or 5986 for HTTPS by default)username- The username name. (Mandatory)password- The password.workingDirectory- Path of the directory for the spawned process on the remote system (can be null)timeout- The timeout in milliseconds (throws an IllegalArgumentException if negative or zero)localFileToCopyList- List of local files to copy to the remote before the executionticketCache- The Ticket Cache pathauthentications- List of authentications. only NTLM if absent- Returns:
- an instance of WindowsRemoteCommandResult with the result of the command
- Throws:
IOException- If an I/O error occurs.TimeoutException- To notify userName of timeoutWindowsRemoteException- For any problem encountered on remote
-