为什么这不起作用?运行命令+变量

时间:2012-04-29 20:20:44

标签: powershell

这不起作用:

$server = "server";
$cmd = "hostname";
C:\Users\ss\Documents\Scripts\PSTools\PsExec.exe \\$server $cmd;

但这会:

$server = "server";
C:\Users\ss\Documents\Scripts\PSTools\PsExec.exe \\$server hostname;

为什么?

1 个答案:

答案 0 :(得分:0)

尝试附加&到命令的前面:

&安培; C:\ Users \ ss \ Documents \ Scripts \ PSTools \ PsExec.exe \ $ server $ cmd;