public class PowerShell extends Object
Once the session is finished, call close() method in order to free the resources.
| Modifier and Type | Field and Description |
|---|---|
static String |
END_SCRIPT_STRING |
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closes all the resources used to maintain the PowerShell context
|
PowerShell |
configuration(Map<String,String> config)
Allows to override jPowerShell configuration using a map of key/value
Default values are taken from file jpowershell.properties, which can be replaced just setting it on project classpath The values that can be overridden are: maxThreads: the maximum number of thread to use in pool. 3 is an optimal and default value waitPause: the pause in ms between each loop pooling for a response. |
PowerShellResponse |
executeCommand(String command)
Launch a PowerShell command.
|
PowerShellResponse |
executeScript(BufferedReader srcReader)
Executed the provided PowerShell script in PowerShell console and gets
result.
|
PowerShellResponse |
executeScript(String scriptPath)
Executed the provided PowerShell script in PowerShell console and gets
result.
|
static PowerShellResponse |
executeSingleCommand(String command)
Execute a single command in PowerShell console and gets result
|
static PowerShell |
openSession()
Creates a session in PowerShell console an returns an instance which allows
to execute commands in PowerShell context.
|
static PowerShell |
openSession(String customPowerShellExecutablePath)
Creates a session in PowerShell console an returns an instance which allows
to execute commands in PowerShell context.
|
public static final String END_SCRIPT_STRING
public PowerShell configuration(Map<String,String> config)
The values that can be overridden are:
config - map with the configuration in key/value formatpublic static PowerShell openSession() throws PowerShellNotAvailableException
PowerShellNotAvailableException - if PowerShell is not installed in the systempublic static PowerShell openSession(String customPowerShellExecutablePath) throws PowerShellNotAvailableException
customPowerShellExecutablePath - the path of powershell executable. If you are using
the default installation path, call openSession() method insteadPowerShellNotAvailableException - if PowerShell is not installed in the systempublic PowerShellResponse executeCommand(String command)
This method launch a thread which will be executed in the already created PowerShell console context
command - the command to call. Ex: dirpublic static PowerShellResponse executeSingleCommand(String command)
command - the command to executepublic PowerShellResponse executeScript(String scriptPath)
scriptPath - the full paht of the scriptpublic PowerShellResponse executeScript(BufferedReader srcReader)
srcReader - the script as BufferedReader (when loading File from jar)public void close()
Copyright © 2018. All rights reserved.