5

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.

MattH
  • 1,975
  • 6
  • 24
  • 31

2 Answers2

4

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.

EBGreen
  • 36,735
  • 12
  • 65
  • 85
  • 2
    The blog post linked to from that page appears to be gone (the Windows Live space doesn't exist, error page says). Does anyone remember what it said for a workaround? – Vimes Jun 27 '11 at 17:12
  • 3
    Sorry to answer my own question. It looks like at least one of the workarounds is implemented here: http://www.snowland.se/2010/02/21/read-msi-information-with-powershell/ – Vimes Jun 27 '11 at 17:43
2

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

Ralph Willgoss
  • 11,750
  • 4
  • 64
  • 67