Powershell - .GetType().InvokeMember() throws Type mismatch Error

1

I am trying to extract certain values from an .msi file with Powershell to help automate an installation. I came across a method involving calling InvokeMember() such as example 1 and example 2.

I tried this myself with the following code -

$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$mSIPath =  $prereqComponent.getAttribute("msiFilename")
$mSIDatabase = $windowsInstaller.GetType().InvokeMember(
    "OpenDatabase", 
    "InvokeMethod", 
    $null, 
    $windowsInstaller, 
    @($mSIPath.FullName, 0) 
)

Whenever I run the above in Powershell v2.0 in Windows 7 SP1 I get the following error -

Exception calling "InvokeMember" with "5" argument(s): "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))" At line:3 char:56

  • $mSIDatabase = $windowsInstaller.GetType().InvokeMember <<<< ("OpenDatabase", "InvokeMethod", $null, $windowsInstaller, @($mSIPath, 0))

    • CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    • FullyQualifiedErrorId : DotNetMethodTargetInvocation

Looking up the error I first thought that maybe it was down to msiFilename but calling Test-Path $mSIPath gives True and it is definitely a working .msi file as I have installed it previously.

After trying to tweak the arguments I am at a loss. Could anyone suggest what I am doing wrong?

sql
powershell
windows-installer
asked on Stack Overflow Jun 22, 2016 by Flash_Steel • edited Jun 22, 2016 by Flash_Steel

1 Answer

1

From the code snippet provided, it looks like your $msiPath should be of type IO.FileInfo.

Since we cannot see the $prereqComponent object classification, it may be useful to assign the fully qualified path name (FQPN, such as: C:\Users\Me\Desktop\File), or ensure the $msiPath above is of type IO.FileInfo.

answered on Stack Overflow Jun 22, 2016 by gravity

User contributions licensed under CC BY-SA 3.0