param(
[Parameter(ValueFromPipeline = $true,HelpMessage = 'Enter CSV path')]
[String[]]$Path = $null
)
if($Path -eq $null)
{
Add-Type -AssemblyName System.Windows.Forms
$Dialog = New-Object -TypeName System.Windows.Forms.OpenFileDialog
$Dialog.InitialDirectory = "$InitialDirectory"
$Dialog.Title = 'Select MSI File'
$Dialog.Filter = 'MSI File|*.MSI'
$Dialog.Multiselect = $true
$Result = $Dialog.ShowDialog()
if($Result -eq 'OK')
{
Try
{
$Path = $Dialog.FileNames
}
Catch
{
$Path = $null
Break
}
}
else
{
#Shows upon cancellation of Save Menu
Write-Host -ForegroundColor Yellow -Object 'Notice: No file(s) selected.'
Break
}
}
$Path = $Dialog.FileName
$comObjWI = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $comObjWI.GetType().InvokeMember('OpenDatabase','InvokeMethod',$null,$comObjWI,@($Path, 0))
$Query = "SELECT Value FROM Property WHERE Property = 'ProductCode'"
$View = $MSIDatabase.GetType().InvokeMember('OpenView','InvokeMethod',$null,$MSIDatabase,($Query))
$View.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $View, $null)
$Record = $View.GetType().InvokeMember('Fetch','InvokeMethod',$null,$View,$null)
$Value = $Record.GetType().InvokeMember('StringData','GetProperty',$null,$Record,1)
$Value