通过PowerShell WinRM传递双引号
发布时间:2020-12-14 04:38:32 所属栏目:Windows 来源:网络整理
导读:我使用此 code在服务器上执行远程代码(MSI安装).通过脚本传递双引号是行不通的.我尝试了下面给出的两个变体(#3和#4)以及输出. 输入#1(在命令中测试双引号的简单情况) powershell.exe -inputformat none -File client.ps1 -target 1.2.3.4 -port 5985 -passwo
我使用此
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 如果echo工作,我应该能够在我正在进行的基于运行空间的使用中将更改合并到MSI命令中. 如果我使用以下内容,MSI设置正常.注意单引号. msiexec /qn /i 'C:setupsMy Software.msi' 但是,我需要传递公共属性,MSI不喜欢单引号.尝试运行以下命令将打开MSI参数对话框. msiexec /qn /i 'C:setupsMy Software.msi' MYPROP='My Value' 从服务器上的本地命令提示符运行此工作正常. msiexec /qn /i "C:setupsMy Software.msi" MYPROP="My Value" 解决方法
如果你是从cmd.exe调用它,你必须根据CMD的规则逃避双引号.
powershell.exe -command "echo "hello world"" 产量 hello world 就个人而言,我建议尽可能避免从命令行传递参数.也许你可以将参数值存储在一个文件中(例如序列化的XML,JSON),并让PowerShell脚本读取文件? 更好的是,我建议通过Start-Process cmdlet对进程(例如msiexec.exe)进行任何操作.这样,您可以在变量中为-ArgumentList参数构建值,然后保证它将以您希望的方式完全传递,此外,您不会受限于cmd的引用规则.可执行程序. 考虑以下: $ArgumentList = '/package "c:setupsMy Software.msi" /passive /norestart /l*v "{0}tempInstall My Software.log" MYPROP="My Value With Spaces"' -f $env:windir; Start-Process -FilePath msiexec.exe -ArgumentList $ArgumentList; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- windows-7 – Windows 7 64位上的FoxPro 2.6 DOS
- windows-server-2008-r2 – mscorsvw.exe(.NET运行时优化服
- Windows Server 2016-Powershell迁移FSMO角色
- windows平台下 使用cmake 编译 fddk-aac源码
- windows – 实时IIS监控
- windows – 如何在VC中创建锁?
- Windows 7 64位计算机上的Ruby安装程序
- 批处理文件 – Windows批处理(cmd.exe)命令行参数和字符串操
- 如何在Windows域中为计算机启用自动登录?
- windows – 匿名,身份验证,模拟和委托有什么区别,为什么委托
推荐文章
站长推荐
- windows-phone-7 – 更改WP7应用程序中的页面?
- 如何向Windows询问系统托盘图标的大小?
- windows-phone-7 – wp7 – 带有大量文本的TextB
- windows-xp – 如何在Windows XP上注销之前运行我
- windows 平台使用 VS2017 编译 libevent 源码
- 许可 – Microsoft如何执行许可?
- winforms – 为什么Windows窗体TextBox中的AutoS
- windows-server-2008 – 将Windows服务器映像备份
- windows-server-2008 – 在Windows 2008 Server上
- windows – 如何强制重启而不是关机(XP)
热点阅读