且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Powershell在远程计算机上使用命令行参数执行远程exe

更新时间:2022-12-22 23:13:28

您尝试使用 -ArgumentList 参数:

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" }