Reputation: 162
Having some weirdness where Powershell is not executing this command correctly. It can't understand the INSTALLFOLDER or TARGETDIR and just throws up the Windows Installer help box.
Whereas command prompt processes this just fine??? It's very weird. PS version is 5.1.18362 I believe.
the command is
msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn
My msi is a Wix installer msi and has the property INSTALLFOLDER
Upvotes: 0
Views: 1093
Reputation: 16116
This is not how you run this command in PowerShell. There are several ways to run external command in PowerShell and it a well-documented use case. Links to follow
• Using PowerShell and external commands and their parameters or switches. Running external commands, always require special consideration.
• PowerShell: Running Executables
• Solve Problems with External Command Lines in PowerShell
• Top 5 tips for running external commands in Powershell
• Using Windows PowerShell to run old command-line tools (and their weirdest parameters)
• Execution of external commands in PowerShell done right https://mnaoumov.wordpress.com/2015/01/11/execution-of-external-commands-in-powershell-done-right
https://mnaoumov.wordpress.com/2015/03/31/execution-of-external-commands-native-applications-in-powershell-done-right-part-2 https://mnaoumov.wordpress.com/2015/04/05/execution-of-external-commands-native-applications-in-powershell-done-right-part-3 http://edgylogic.com/blog/powershell-and-external-commands-done-right
https://trevorsullivan.net/2016/07/20/powershell-quoting
PowerShell has a list of characters that mean specific things, vs what cmd.exe implementation means, and if you need those, they must be properly terminated. See the below
So, to make your command work in the PowerShell consolehost, ISE, VSCode, do something like this...
# Using teh Call operator
& 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'
or
... this...
# Using Start-Process
$ConsoelCommand = 'msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn'
Start-Process powershell -ArgumentList "-NoExit","-Command &{ $ConsoleCommand }" -Wait
Upvotes: 1
Reputation: 357
Make sure you check for existence of that actual folder, but it's likely the problem is the space
instead of this:
msiexec.exe /i "C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi" INSTALLFOLDER="C:\Installation Test" /qn
try this:
invoke-command -scriptblock {cmd /c "msiexec.exe /i `"C:\Users\sadas\aasasdd\sda\asdasd\19526-Debug-x64.msi`" INSTALLFOLDER=`"C:\Installation` Test`" /qn"}
Notice that all the double-quotes are escaped AND a the space in "C:\Installation Test" is escaped. Your problem will boil down to this space and how you handle it. Also try changing double to single quotes. If you decide to use variables in your command, definitely add the strings (""+"") to create the command so that it will expand the variables correctly.
Upvotes: 1