Powershell Execute remote exe with command line arguments on remote computer

后端 未结 5 1839
粉色の甜心
粉色の甜心 2020-12-01 12:10

I\'ve searched all over and tried different variations of commands, but I am still not there yet.

My goal is to run an exe that already resides on a remote machine a

5条回答
  •  自闭症患者
    2020-12-01 13:01

    Did you try using the -ArgumentList parameter:

    invoke-command -ComputerName studio -ScriptBlock { param ( $myarg ) ping.exe $myarg } -ArgumentList localhost   
    

    http://technet.microsoft.com/en-us/library/dd347578.aspx

    An example of invoking a program that is not in the path and has a space in it's folder path:

    invoke-command -ComputerName Computer1 -ScriptBlock { param ($myarg) & 'C:\Program Files\program.exe' -something $myarg } -ArgumentList "myArgValue"
    

    If the value of the argument is static you can just provide it in the script block like this:

    invoke-command -ComputerName Computer1 -ScriptBlock { & 'C:\Program Files\program.exe' -something "myArgValue" } 
    

提交回复
热议问题