Q:

Powershell function returns string but client gets array

The function below would seem to return a string.  The diagnostic output (in my test) is 
return value should be string.  Length is 30
However the user of the function receives an object array of length two. The first element is null, and the second one is the expected string result. 
Can this be explained?  You can test this by running it against any .MSI file. Try something as simple as (GetproductNameFromMsi c:\temp\myproduct.msi).length.  In a repro, this would return 2, while the diagnostic line shows a different result.  (Unless you have a 2-character product name!)
function GetProductNameFromMsi
{
    param([string]$msiPathAndFile)  
    $windowsInst = New-Object -com WindowsInstaller.Installer
    $database = $windowsInst.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $windowsInst, @($msiPathAndFile, 0))
    $view = $database.GetType().InvokeMember('OpenView', 'InvokeMethod', $Null, $database, ("SELECT * FROM Property WHERE Property ='ProductName'"))
    $view.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $view, $Null)
    $record = $view.GetType().InvokeMember('Fetch', 'InvokeMethod', $Null, $view, $Null)
    $productName = $record.GetType().InvokeMember('StringData', 'GetProperty', $null, $record, 2)
    write-host "return value should be $($productName.GetType()).  Length is $($productName.Length)"
    return $productName
}

A:

The problem is $view.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $view, $Null) which returns something.
Try this:
[void] $view.GetType().InvokeMember('Execute', 'InvokeMethod', $Null, $view, $Null)

