I\'ve got a simple problem. I\'ve only found two ways that will actually run my msi file, and neither of them will work.
Pay close attention to my usage of \'
PowerShell Module: There is now a Windows Installer PowerShell Module courtesy of Heath Stewart of Microsoft. I haven't tested it much, just a smoke test. See below for another alternative using MSI API directly via COM.
Re-Quoting: I saw someone write a lot about PowerShell and escape sequences. It looks pretty complicated: Setting Public Property Values on the Command Line - there were other posts too.
Alternatives?: Perhaps you can go via MSI API COM
calls? I have this old answer on various ways to uninstall MSI packages. I'll see if I can dig up a PowerShell example, in the meantime here is a VBScript version using MSI API COM calls
:
Set installer = CreateObject("WindowsInstaller.Installer")
installer.InstallProduct "C:\Product.msi", "REBOOT=ReallySuppress"
There is also WMI
- which I never use. See section 10 here.
Link:
Powershell treats everything between single quotes as a literal string. Your variables won't get expanded if you use single quotes. So you need to use double quotes if you want to use variable expansion.
The problem with your example with the double quotes is that powershell interprets all the characters until a whitespace as a single variable. And since "$Basics\Installer_.64 bit_.msi" is not the variable that you want, this doesn't work either. You can put your variable name between curly brackets ({}) to delimit it from the rest of the string. So an example that would work is this:
Start-Process msiexec.exe -Wait -ArgumentList "/i ${Basics}\Installer_.64 bit_.msi"
Another option would be to use the format string operator:
'/i {0}\Installer_.64 bit_.msi' -f $Basics
This operator gives you a lot more freedom and you can do some very advanced string formatting with it. Another added benefit is that this way you can use single quotes. This makes sure that no expansion will take place. For example, in case your msi files have dollar signs in the name, the first example will not work, since powershell will try to expand the variables.