Run a powershell on a remote machine using JAVA

后端 未结 1 833
难免孤独
难免孤独 2020-12-22 01:47

I want to run a powershell in some remote machine using java. How can this be achieved.? currently this code is not running the powershell command locally.!!

<         


        
相关标签:
1条回答
  • 2020-12-22 02:39

    You can try to run something like "invoke-command -computername Server1 -filepath c:\scripts\script.ps1"

        Process p = new ProcessBuilder()
                .inheritIO()
                .command("invoke-command", "-computername", "Server1",
                        "-filepath", "C:\\scripts\\script.ps1").start();
        p.waitFor();
    

    but first of all make sure that this command work OK from command line.

    0 讨论(0)
提交回复
热议问题