Flash_Steel Flash_Steel - 1 year ago 411
SQL Question

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

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(
@($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,

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

    • FullyQualifiedErrorId : DotNetMethodTargetInvocation

Looking up the error I first thought that maybe it was down to
but calling
Test-Path $mSIPath
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download