powershell - 将 msiexec 命令从 cmd 转换为 powershell
问题描述
在我的powershell
脚本中,我需要msiexec
安静地运行几个命令。问题是当我尝试运行命令时,Windows Installer 帮助弹出窗口显示而不是执行命令。(下图)
相同的命令在 cmd 中运行良好。下面是我的命令。我&
将命令中的 in 保留在双引号中,以按照建议将其视为字符串。
& msiexec /log c:\msxml.log /quiet /I "&" D:\LoadGeneratorsetup\prerequisites\msxml6\msxml6_x64.msi
我尝试使用Start-Process -FilePath
它来运行它,但最终出现以下错误。
Start-Process : A positional parameter cannot be found that accepts argument 'c:\msxml.log'.
At line:1 char:1
+ Start-Process -FilePath msiexec /log c:\msxml.log /quiet /I "&" D:\Lo ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [Start-Process], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.StartProcessCommand
有人可以提供有关如何使用 powershell 安静地执行命令的详细信息。
解决方案
对于您的第二个命令:
& msiexec /i "& D:\LoadGeneratorsetup\HP_LoadGenerator.msi" /qb /l*vx "& D:\LoadGeneratorsetup\Logs\InstallationLogs"+"_"+(Get-Date -Format "yyyy-MM-dd-hh-mm-s")+".txt"
您有两个选择,要么将日志路径设置为变量,要么只将路径括起来:
1 - 设置为变量
$logfile = "D:\LoadGeneratorsetup\Logs\InstallationLogs" + "_" + (Get-Date -Format "yyyy-MM-dd-hh-mm-s") + ".txt"
msiexec /i "D:\LoadGeneratorsetup\HP_LoadGenerator.msi" /qb /l*vx $logfile
2 - 将路径括起来
msiexec /i "D:\LoadGeneratorsetup\HP_LoadGenerator.msi" /qb /l*vx ("D:\LoadGeneratorsetup\Logs\InstallationLogs" + "_" + (Get-Date -Format "yyyy-MM-dd-hh-mm-s") + ".txt")
我假设该命令只是在运行命令之前不评估日志路径。
推荐阅读
- hadoop - 无法在 ubuntu 18.04 中启动 hadoop datanode hadoop 3.1.1
- selenium-ide - 如何在 Selinium Ide 中使用“运行”命令?
- javascript - 在单击画布的位置添加一个点
- c++ - 如何在 C++ 的输出中打印引号?
- android - ionic GeoLocation 检索地址?
- wpf - 除非检查注册表,否则如何更改 WPF 的版本?
- powershell - 新的本地用户/本地组路径?
- javascript - 无法导入和导出类
- eclipse - 尝试将 sonarlint 连接到 sonarqube 服务器时发生空指针异常
- swift - heightAnchor.constraint 不改变视图高度