Are you aware of some Java APIs/Libraries for remote PowerShell invocation?
From this API I need things like:
You can use JPowerShell library: https://github.com/profesorfalken/jPowerShell
PowerShell powerShell = null;
try {
//Creates PowerShell session
PowerShell powerShell = PowerShell.openSession();
//Increase timeout to give enough time to the script to finish
Map<String, String> config = new HashMap<String, String>();
config.put("maxWait", "80000");
//Execute script
PowerShellResponse response = powerShell.configuration(config).executeScript("./myPath/MyScript.ps1");
//Print results if the script
System.out.println("Script output:" + response.getCommandOutput());
} catch(PowerShellNotAvailableException ex) {
//Handle error when PowerShell is not available in the system
//Maybe try in another way?
} finally {
//Always close PowerShell session to free resources.
if (powerShell != null)
powerShell.close();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With