问题
In my powershell
script, I need to run couple of msiexec
commands quietly. The problem is when I try to run the command, the Windows Installer help popup shows rather than executing the command. (Below Image)
The same command runs well in cmd. Below is my command. I have kept the &
in the command in double quotes to consider it as a string as suggested.
& msiexec /log c:\msxml.log /quiet /I "&" D:\LoadGeneratorsetup\prerequisites\msxml6\msxml6_x64.msi
I tried using Start-Process -FilePath
to run this but end up with the below error.
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
Can someone provide an details on how to execute the command quietly using powershell.
回答1:
For your second command:
& msiexec /i "& D:\LoadGeneratorsetup\HP_LoadGenerator.msi" /qb /l*vx "& D:\LoadGeneratorsetup\Logs\InstallationLogs"+"_"+(Get-Date -Format "yyyy-MM-dd-hh-mm-s")+".txt"
You have two options, either set the log path to a variable or just bracket the path:
1 - Set to variable
$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 - Bracket the path
msiexec /i "D:\LoadGeneratorsetup\HP_LoadGenerator.msi" /qb /l*vx ("D:\LoadGeneratorsetup\Logs\InstallationLogs" + "_" + (Get-Date -Format "yyyy-MM-dd-hh-mm-s") + ".txt")
I am assuming that the command is just not evaluating the log path before running the command.
回答2:
I want to alert you to the Windows Installer PowerShell Module on github.com. Scroll down on this front page for description and some samples, see releases tab for download. I haven't really tested it much, but it is from Heath Stewart - Microsoft Senior Software Engineer (github).
Brief, inline sample:
install-msiproduct .\example.msi -destination (join-path $env:ProgramFiles Example)
Some Additional Links:
- How can I use powershell to run through an installer?
- Get the Windows Installer PowerShell Module easier with WMF 5.0
来源:https://stackoverflow.com/questions/50693426/converting-msiexec-command-from-cmd-to-powershell