5
votes

I'm trying to modify the contents of an MSI file using Powershell. To do so I create an instance of a WindowsInstaller.Installer then use $installer.OpenDatabase and $database.OpenView. Similar functionality works in VBScript and I've seen samples on-line that appear to work.

$installer = new-object -comobject "WindowsInstaller.Installer"
$database = $installer.OpenDatabase("C:\Temp\Setup.msi", 1)

For the above code, I get an error "Method invocation failed because [System.__ComObject] doesn't contain a method named 'OpenDatabase'."

$installer = new-object -comobject "WindowsInstaller.Installer"
$database = $installer.InvokeMethod("OpenDatabase","C:\Temp\Setup.msi", 1)

If I attempt to use $installer.InvokeMethod I get the same error "Method invocation failed because [System.__ComObject] doesn't contain a method named 'InvokeMethod'."

Any help would be much appreciated.

Thanks.

2

2 Answers

4
votes

See the this thread for some guidance. Basically the MSI COM object is implemented in a way that confuses PS. There is a link to a blog post discussing it in that thread.

2
votes

The originally accepted answer link, is no longer valid.

In the comments, JohnB has posted a link that has a great example of how to use the Windows Installer from Powershell.

There's also a CodePlex project that wraps a lot functionality and could be useful:
Windows Installer PowerShell Module