堆垛機,
我正在嘗試(從 Chrome Enterprise 的 MSI)獲取版本號。在我將 Chrome 下載為 .MSI 后,我注意到我可以看到許多屬性。我希望能夠訪問和構建“if 陳述句”的一個是“評論”部分。

當我嘗試使用 Get-Item 并將其格式化為串列時,它說那里沒有任何內容,我似乎無法確定要做什么。
(Get-Item ".\Chrome.msi").VersionInfo | fl
該命令回傳:

如何提取“評論”部分和其中的資料?
uj5u.com熱心網友回復:
這些屬性不存盤在orSystem.IO.FileInfo回傳的物件中。一個解決方案是使用COM 物件為您檢索這些屬性:Get-ItemGet-Commandshell.application
$filePath = ".\Chrome.msi"
$parentPath = (Resolve-Path -Path (Split-Path -Path $filePath)).Path
$fileName = Split-Path -Path $filePath -Leaf
$shell = New-Object -COMObject Shell.Application
$shellFolder = $Shell.NameSpace($parentPath)
$shellFile = $ShellFolder.ParseName($fileName)
$shellFolder.GetDetailsOf($shellFile,24)
24, 是您所關注的特定屬性的 ID,因此在這種情況下,獲取該資訊需要注釋。.GetDetailsOf(.,.)幸運的是,我在嘗試決議評論之前遇到了這個問題。我不記得在哪里,但是我找到了上面提出的解決方案,所以當我能再次找到它時,我會鏈接它。
uj5u.com熱心網友回復:
您可以使用 Get-AppLockerFileInformation 獲取 MSI 屬性“ProductVersion”:
Get-AppLockerFileInformation -Path "C:\PathTo\my.msi" | Select -ExpandProperty Publisher | select BinaryVersion
uj5u.com熱心網友回復:
我的觀點是從互聯網上拼湊而成的。
$msifile = 'C:\googlechromestandaloneenterprise64.msi'
function Which-MSIVersion {
<#
.SYNOPSIS
Function to Check Version of an MSI file.
.DESCRIPTION
Function to Check Version of an MSI file for comparision in other scripts.
Accepts path to single file.
.PARAMETER msifile
Specifies the path to MSI file.
.EXAMPLE
PS> Which-MSIVersion -msifile $msifile
68.213.49193
.NOTES
General notes
#>
param (
[Parameter(Mandatory = $true, HelpMessage = 'Specifies path to MSI file.')][ValidateScript({
if ($_.EndsWith('.msi')) {
$true
} else {
throw ("{0} must be an '*.msi' file." -f $_)
}
})]
[String[]] $msifile
)
$invokemethod = 'InvokeMethod'
try {
#calling com object
$FullPath = (Resolve-Path -Path $msifile).Path
$windowsInstaller = New-Object -ComObject WindowsInstaller.Installer
## opening database from file
$database = $windowsInstaller.GetType().InvokeMember(
'OpenDatabase', $invokemethod, $Null,
$windowsInstaller, @($FullPath, 0)
)
## select productversion from database
$q = "SELECT Value FROM Property WHERE Property = 'ProductVersion'"
$View = $database.GetType().InvokeMember(
'OpenView', $invokemethod, $Null, $database, ($q)
)
##execute
$View.GetType().InvokeMember('Execute', $invokemethod, $Null, $View, $Null)
## fetch
$record = $View.GetType().InvokeMember(
'Fetch', $invokemethod, $Null, $View, $Null
)
## write to variable
$productVersion = $record.GetType().InvokeMember(
'StringData', 'GetProperty', $Null, $record, 1
)
$View.GetType().InvokeMember('Close', $invokemethod, $Null, $View, $Null)
## return productversion
return $productVersion
}
catch {
throw 'Failed to get MSI file version the error was: {0}.' -f $_
}
}
Which-MSIVersion -msifile $msifile
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/467586.html
