Generally, if invoking msiexec
does nothing but show a dialog describing the command-line syntax, the implication is that there's a syntax problem.
The likely source of the syntax error is that the "..."
string you're using as the -arg
argument (full name: -Args
or -ArgumentList
) has $file
embedded in it without embedded quoting:
That is, if the value of $file
has embedded spaces, for instance (e.g., C:Msi Installersfoo.msi
), the resulting msiexec
command will be syntactically invalid, because the space-separated tokens of the path are each considered an argument.
Bill_Stewart's helpful answer shows you how to use embedded quoting around $file
to solve this problem, by enclosing it in `"
(`
is PowerShell's escape character).
If you were to stick with passing the arguments as a single string, you would use:
Start-Process msiexec.exe -Args "/I `"$file`" /qb ADDLOCAL=ALL ALLUSERS=TRUE" -Wait
Arguably, however, it's cleaner not to pass a single, command-line-like string as the only argument, but to instead pass the arguments as elements of an array, which is indeed what -ArgumentList
/ -Args
was designed to accept (its parameter type is [string[]]
):
Start-Process msiexec.exe -Args /I, `"$file`", /qb, ADDLOCAL=ALL, ALLUSERS=TRUE -Wait
Note how $file
is still passed with embedded quoting, which is unfortunately required due to a bug in Start-Process
(as of Windows PowerShell v5.1 / PowerShell Core v7.1); it looks like this bug will not get fixed, however, but the linked GitHub report suggests introducing a new
-ArgumentArray
parameter with the correct behavior.
You may alternatively build up the array of arguments in advance; note how this is done in expression mode (with syntax more like regular programming languages), so the array elements all require quoting; also note how I'm using single quotes to define literal arguments:
# Create the array of arguments to pass to msiexec
$msiArgs =
'/I',
"`"$file`"", #`# !! enclosing in `"...`" is needed due to the bug mentioned above
'/qb',
'/ADDLOCAL=ALL',
'ALLUSERS=TRUE'
Start-Process msiexec.exe -Args $msiArgs -Wait