title: How gathering following output to a csv file
body: <p>My script gathering msi information such as ProductCode, ProductName, Upgrade Code etc..
  I am trying to get all information what in CLI read export a csv file. </p>
  
  <p>Here is a piece of code, the rest is also similar</p>
  
  <pre><code>$Dir =  Get-ChildItem -Path W:\MSIs\*.msi -Recurse
  
  foreach ($item in $Dir) { 
  
  try {
      $windowsInstaller = New-Object -com WindowsInstaller.Installer
  
      $database = $windowsInstaller.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $null, $windowsInstaller, @((Get-Item -Path $item).FullName, 0))
  
      $view = $database.GetType().InvokeMember('OpenView', 'InvokeMethod', $null, $database, ("SELECT Value FROM Property WHERE Property = 'ProductName'"))
      $view.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $view, $null)
  
      $record = $view.GetType().InvokeMember('Fetch', 'InvokeMethod', $null, $view, $null)
  
     echo "Product Name"
      Write-Output -InputObject $($record.GetType().InvokeMember('StringData', 'GetProperty', $null, $record, 1))
  
  } catch {
      Write-Error -Message "Product Name" $_.ToString()s
  
      break
  }
  </code></pre>