I stuck at a problem by reading multiple non static values from a Msi file with powershell. Are there any Ideas?
I want read non static values from a Msi tables.
I can actually read static values from the table Properties, but one by one. like this function readMsiProperties($msifile, $Property) {
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($msiFile, 0))
$Query = "SELECT Value FROM Property WHERE Property = '$Property'"
try {
$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)
# Commit database and close view
$MSIDatabase.GetType().InvokeMember("Commit", "InvokeMethod", $null, $MSIDatabase, $null)
$View.GetType().InvokeMember("Close", "InvokeMethod", $null, $View, $null)
$MSIDatabase = $null
$View = $null
return $Value
#Catch NullValues if a Query is not correct or not in the MSI File
}
Catch {
}
}
This works perfeclty for the Property table. But if i want to read something from Serviceinstall table, there are no static values i can use like an anchor.
if i try it in this way i get an "InvokeMember with 5 Arguments exception" for the Variable $view.
function readMsiServiceTable($msifile) {
#try{
# Read property from MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @($msiFile, 0))
$Query = "SELECT '*' FROM 'ServiceInstall' "
try {
$View = $MSIDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $MSIDatabase, ($Query))
So what can i do instead. the Idea ist to read this non static values into an array or a list to work with it.
Thanks!!