【发布时间】:2014-01-16 18:55:04
【问题描述】:
我正在使用这个code 在服务器上执行远程代码(MSI 安装)。通过脚本传递双引号是行不通的。我尝试了下面给出的两种变体(#3 和 #4)以及输出。
输入#1(测试命令中双引号的简单案例)
powershell.exe -inputformat none -File client.ps1 -target 1.2.3.4 -port 5985 -password "pass" -username "user" -command "echo hello"
输出(作品)
hello
输入 #2(可以理解,这行不通)
powershell.exe -inputformat none -File client.ps1 -target 1.2.3.4 -port 5985 -password "pass" -username "user" -command "echo hello world"
输出
hello
world
输入 #3
powershell.exe -inputformat none -File client.ps1 -target 1.2.3.4 -port 5985 -password "pass" -username "user" -command "echo `"hello world`""
输出(另一个词怎么了?)
hello
输入 #4
powershell.exe -inputformat none -File client.ps1 -target 1.2.3.4 -port 5985 -password "pass" -username "user" -command @'
>> echo "hello world"
>> '@
>>
输出(同样,缺少第二个单词)
hello
如果回显有效,我应该能够在我正在做的基于运行空间的使用中合并对 MSI 命令的更改。
如果我使用以下设置,MSI 设置工作正常。注意单引号。
msiexec /qn /i 'C:\setups\My Software.msi'
但是,我需要传递公共属性,而 MSI 不喜欢其中的单引号。尝试运行以下命令会打开 MSI 参数对话框。
msiexec /qn /i 'C:\setups\My Software.msi' MYPROP='My Value'
从服务器上的本地命令提示符运行它可以正常工作。
msiexec /qn /i "C:\setups\My Software.msi" MYPROP="My Value"
【问题讨论】:
标签: powershell windows-installer winrm runspace