ReadMSIMSTInfos.ps1
<#
usage : .\ReadMSIMSTInfos.ps1 -msifldr <MSI or MST & MST folder path>
return: MST or (if not exist MST: MSI) informations
#>
param($msifldr)
$erroractionpreference = 'silentlycontinue'
$here = $PSScriptRoot; if(!$here){$here = (Get-Location).path}
if(!$msifldr){$msifldr = $here}
$SourceMSIMST = (Get-ChildItem -path $msifldr | Where-Object{$_.name.split('.')[-1] -match "mst"}).fullname
$SourceMSI = (Get-ChildItem -path $msifldr | Where-Object{$_.name.split('.')[-1] -match "msi"}).fullname
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
[System.Collections.ArrayList]$MSIMSTInfos = @()
$Query = "SELECT Property, Value FROM Property"
if($SourceMSIMST){
$val = [pscustomobject]@{'Name'='FileType';'value'='MST'}; $MSIMSTInfos.add($val) | Out-Null; $val=$null
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $WindowsInstaller, @($SourceMSI, 2))
$null = $MSIDatabase.GetType().InvokeMember('ApplyTransform', 'InvokeMethod', $Null, $MSIDatabase, @($SourceMSIMST, $null, 0))
}
else{
$val = [pscustomobject]@{'Name'='FileType';'value'='MSI'}; $MSIMSTInfos.add($val) | Out-Null; $val=$null
$SourceMSIMST = $SourceMSI
$MSIDatabase = $WindowsInstaller.GetType().InvokeMember('OpenDatabase', 'InvokeMethod', $Null, $WindowsInstaller, @($SourceMSI, 0))
}
# Opens a data view to the MSI based on the query created.
$View = $MSIDatabase.GetType().InvokeMember('OpenView', 'InvokeMethod', $null, $MSIDatabase, $Query)
$null = $View.GetType().InvokeMember('Execute', 'InvokeMethod', $null, $View, $null)
while ($Record = $View.GetType().InvokeMember('Fetch', 'InvokeMethod', $null, $View, $null)) {
$name = $Record.GetType().InvokeMember('StringData', 'GetProperty', $null, $Record, 1)
$value = $Record.GetType().InvokeMember('StringData', 'GetProperty', $null, $Record, 2)
$val = [pscustomobject]@{'Name'=$name;'value'=$value}; $MSIMSTInfos.add($val) | Out-Null; $val=$null
}
# Fermer la vue des données MSI
$null = $View.GetType().Invo
return $MSIMSTInfos
/image%2F0881799%2F20140610%2Fob_a8c7fe_logo2.jpg)
Commenter cet article