1

I've read that you can pass arguments to a .msi file, but I have no idea how to do it correctly. I've tried the following, where $ArgumentList is an array.

$ArgumentList = @("/i .\NSClient v67.msi", "/norestart", "/quiet", "/l*v '$directory'", "token=$token", "host=$_host", "mode=$mode")
Start-Process "msiexec" -ArgumentList $ArgumentList -Wait -NoNewWindow

This is part of my script, where I'm trying to install NetSkope on my machine by executing a command. In theory, the command should look like msiexec /i "NSClient v67.msi" token=loremipsum host=bryan.goskope.com mode=peruserconfig /norestart /quiet /l*v "C:\Temp\NetskopeInstallation.log.

#Find file path
$rawPath = Invoke-Expression -Command 'C:\Windows\System32\WHERE /r C:\Users\ /f NSClient*.msi'

#Extract the directory
$filePath = Invoke-Expression -Command "cmd.exe --% /c FOR /f ""tokens=1"" %A IN ($rawPath) DO (ECHO 
'%~dpA')"

#Cast $filePath to work with string methods
$filePath = Out-String -InputObject $filePath
$filePath = $filePath.split("'")[1]

Invoke-Expression -Command "cmd.exe --% /c cd $filePath"


$ArgumentList = @("/i .\NSClient v67.msi", "/norestart", "/quiet", "/l*v '$directory'", 
"token=$token", "host=$_host", "mode=$mode")
Start-Process "msiexec" -ArgumentList $ArgumentList -Wait -NoNewWindow
Bryan Arreola
  • 197
  • 1
  • 6
  • 22
  • 1
    Please check this: [PowerShell MSI Module](https://stackoverflow.com/a/58141208/129130) and [secondary](https://stackoverflow.com/a/53436779/129130). Please check the different links contained in these two base answers, there are links to what you directly ask as well. Direct link to github.com: https://github.com/heaths/psmsi – Stein Åsmul Dec 05 '19 at 23:57
  • 1
    I would use Heath's module as Stein mentions. I would also rename your MSI and remove the space to avoid that one more issue with debugging. Once you've got it working you can always put the space back. – Doc Dec 06 '19 at 12:03

2 Answers2

0

I would also recommend using the Powershell MSI Module
Concerning Start-Process:
-Argumentlist expects string as a type. I don't think you can just pass an array.
You also need to surround the parameters that require a space with escaped double quotes. The escape character is powershell is the grave-accent(`).
Another problem is that the variable $directory will never be expanded, because it is surrounded with single quotes. You need to remove those.
The following should work for your example, but I personally would just remove the space in the file name, since you don't need to do weird stuff with escaping.

Without escaping:

$ArgumentList = "/i .\NSClientv67.msi /norestart /quiet /l*v $directory token=$token host=$_host mode=$mode"

With escaping:

$ArgumentList = "/i `".\NSClient v67.msi`" /norestart /quiet /l*v $directory token=$token host=$_host mode=$mode"
0

Here's a slightly different syntax:

$MSIArguments = @(
    "/x"
    "`"C:\path with spaces\test.msi`""
    "/qb"
    "/norestart"
    "/l*v"
    "`"C:\path with spaces\test.log`""
)

Start-Process "msiexec.exe" -ArgumentList $MSIArguments -Wait -NoNewWindow 
Captain_Planet
  • 1,228
  • 1
  • 12
  • 28