1

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)

enter image description here

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.

sdgd
  • 723
  • 1
  • 17
  • 38
  • 1
    Just get rid of the "&" and the & at the start so :: msiexec /log c:\msxml.log /quiet /I D:\LoadGeneratorsetup\prerequisites\msxml6\msxml6_x64.msi – Owain Esau Jun 05 '18 at 06:51
  • Thanks Owain. it worked after removing both the &. But one last `msiexec` is stilling giving the Windows Installer popup. The command looks like below - `& 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 tried removing all the & but still the same. can you help me here. – sdgd Jun 05 '18 at 07:12
  • Check my answer – Owain Esau Jun 05 '18 at 07:25
  • Please see my answer below for some links to [**the Windows Installer PowerShell Module**](https://github.com/heaths/psmsi). – Stein Åsmul Jun 05 '18 at 09:48

2 Answers2

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.

Owain Esau
  • 1,876
  • 2
  • 21
  • 34
  • Yes, you are right. I just tried just giving a static file name and it worked. Thanks for the help Owain. I'll use any of the above option and set the file name. – sdgd Jun 05 '18 at 07:30
  • Owain - one query - the command `& D:\LoadGeneratorsetup\prerequisites\vc2005sp1_mfc_security_update_x86\vcredist_x86.exe /q:a /c:"msiexec /i vcredist.msi /qn"" "` is getting executed without any errors but it's not getting installed. When i run the same in cmd, its executing and installing. is the `msiexec` in the command making it to not execute in PS ? please clarify. – sdgd Jun 05 '18 at 08:02
0

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:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • thanks, will look into it. if you can help me on this command.. `D:\LoadGeneratorsetup\prerequisites\vc2005sp1_mfc_security_update_x86\vcredist_x86.exe /q:a /c:"msiexec /i vcredist.msi /qn"" "` is perfectly working in cmd but not in powershell. i have a similar command (2008 inplace of 2005 in the command) which is running fine both in cmd and PS. not sure what am i missing here. – sdgd Jun 05 '18 at 10:14
  • Not familiar with this, but why don't you run `vcredist_x86.exe` directly in silent mode as explained when you do `vcredist_x86.exe /?` and get the command line options? Not sure you need to deal with the MSI at all. – Stein Åsmul Jun 05 '18 at 10:34
  • I tried with `D:\LoadGeneratorsetup\prerequisites\vc2005sp1_mfc_security_update_x86\vcredist_x86.exe /quiet /norestart` but it says "command line option syntax error" so it is looking for parameters – sdgd Jun 05 '18 at 11:00
  • Sorry, can't investigate this right now. [Maybe have a quick look at this](https://stackoverflow.com/questions/5985961/why-cant-vcredist-x86-exe-installed-quietly/17341974). – Stein Åsmul Jun 05 '18 at 11:05
  • Great. The convention is to create a new question for largely unrelated "follow-up" questions - maybe consider that for the future - there is a lot of moderation here on SO. Glad that simple link helped though! – Stein Åsmul Jun 07 '18 at 16:36