powershell PowerShell:读取Windows Installer(MSI)数据库的函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell PowerShell:读取Windows Installer(MSI)数据库的函数相关的知识,希望对你有一定的参考价值。
function Get-MSIProperties {
PARAM (
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="MSI Database Filename",ValueFromPipeline=$true)]
[Alias("Filename","Path","Database","Msi")]
$msiDbName
)
# A quick check to see if the file exist
if(!(Test-Path $msiDbName)){
throw "Could not find " + $msiDbName
}
# Create an empty hashtable to store properties in
# Creating WI object and load MSI database
$WindowsInstaller = New-Object -ComObject WindowsInstaller.Installer
$WindowsInstallerDatabase = $WindowsInstaller.GetType().InvokeMember("OpenDatabase", "InvokeMethod", $null, $WindowsInstaller, @(($msiDbName),0))
# Open the Property-view
$WindowsInstallerDatabaseView = $WindowsInstallerDatabase.GetType().InvokeMember("OpenView", "InvokeMethod", $null, $WindowsInstallerDatabase, "SELECT * FROM Property")
$WindowsInstallerDatabaseView.GetType().InvokeMember("Execute", "InvokeMethod", $null, $WindowsInstallerDatabaseView, $null)
Remove-Variable Results -ErrorAction SilentlyContinue
$Results = @()
# Loop thru the table
$WindowsInstallerDatabaseRow = $WindowsInstallerDatabaseView.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $WindowsInstallerDatabaseView, $null)
while($WindowsInstallerDatabaseRow -ne $null) {
# Add property and value to hash table
$name = $WindowsInstallerDatabaseView.GetType().InvokeMember("StringData", "GetProperty", $null, $WindowsInstallerDatabaseRow, 1)
$value = $WindowsInstallerDatabaseView.GetType().InvokeMember("StringData", "GetProperty", $null, $WindowsInstallerDatabaseRow, 2)
$Results += New-Object -TypeName PSObject -Property @{$name=$value}
# Fetch the next row
$WindowsInstallerDatabaseRow = $WindowsInstallerDatabaseView.GetType().InvokeMember("Fetch", "InvokeMethod", $null, $WindowsInstallerDatabaseView, $null)
}
$WindowsInstallerDatabaseView.GetType().InvokeMember("Close", "InvokeMethod", $null, $WindowsInstallerDatabaseView, $null)
# Return the hash table
return $Results
}
以上是关于powershell PowerShell:读取Windows Installer(MSI)数据库的函数的主要内容,如果未能解决你的问题,请参考以下文章
powershell PowerShell:使用.NET读取远程注册表值
为啥我的Windows powershell读取结果有一堆90m
powershell PowerShell:读取Windows Installer(MSI)数据库的函数
powershell Powershell函数从文件中读取哈希表文本表示并将其转换为哈希表对象
jar 文件的版本,通过使用 powershell 读取其清单
如何使用 Powershell 读取登录事件和查找用户信息?