sdgd
sdgd

Reputation: 733

Converting msiexec command from cmd to powershell

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.

Upvotes: 1

Views: 2831

Answers (2)

Stein Åsmul
Stein Åsmul

Reputation: 42126

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:

Upvotes: 0

Owain Esau
Owain Esau

Reputation: 1922

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.

Upvotes: 1

Related Questions