Rod Asked: 2025-02-06 07:19:19 +0800 CST2025-02-06 07:19:19 +0800 CST 2025-02-06 07:19:19 +0800 CST 尝试在 powershell 中提取 msi 文件元数据 772 给定: PowerShell 5.1 有人可以帮我从 msi 文件中提取元数据吗? 我已尝试以下操作,但没有评论属性。 $filePath = "C:\Users\user1\source\repos\PRACTICE\WpfApp1\SetupProject1\bin\Debug\SetupProject1.msi" $fileProperties = Get-ItemProperty -Path $filePath $fileProperties | Format-List * powershell 1 个回答 Voted Best Answer Santiago Squarzon 2025-02-06T08:24:57+08:002025-02-06T08:24:57+08:00 您可以尝试使用Shell.ApplicationCOM 对象来提取元数据,我不知道如何提取Comments,但有一种方法可以将其中的所有元数据提取到有序字典中。 # using PowerShell msi for the example $path = 'path\to\PowerShell-7.5.0-win-x86.msi' $shell = New-Object -ComObject Shell.Application $dir = $shell.NameSpace([System.IO.Path]::GetDirectoryName($path)) $item = $dir.ParseName([System.IO.Path]::GetFileName($path)) $metadata = [ordered]@{} for ($id = $nullCounter = 0; $nullCounter -lt 10; $id++) { $key = $dir.GetDetailsOf($null, $id) $value = $dir.GetDetailsOf($item, $id) if ($key -and $value) { $metadata[$key] = $value $nullCounter = 0 continue } if ($id -lt 320) { continue } $nullCounter++ } 然后从这里您应该拥有所有的文件元数据$matadata,并且假设它有一个Comments密钥,您可以执行以下操作: $metadata['Name'] # PowerShell-7.5.0-win-x86.msi $metadata['Comments'] # PowerShell for every system $metadata['Title'] # Installation Database $metadata['Subject'] # PowerShell package $metadata['Authors'] # Microsoft Corporation
您可以尝试使用
Shell.Application
COM 对象来提取元数据,我不知道如何提取Comments
,但有一种方法可以将其中的所有元数据提取到有序字典中。然后从这里您应该拥有所有的文件元数据
$matadata
,并且假设它有一个Comments
密钥,您可以执行以下操作: